Loading jQuery on Gento only if it has not been loaded before

Asked

Viewed 418 times

0

I need my module to only load the jQuery if he hasn’t already clicked on the page, I did it by javascript, but it runs very fast, even using 'setInterval' and etc.. In some cases they continue to pass without waiting for the jQuery load, my question would be:

How can I carry the jQuery with my module only if it has not been loaded before?

1 answer

1

I found a script on SOEN that can help you, try adding this block of script on the page that needs to perform validation:

<script>
if(!window.jQuery) // verifica se foi carregado
{
   var script = document.createElement('script');
   script.type = "text/javascript";
   script.src = "path/to/jQuery"; //caminho para carregar
   document.getElementsByTagName('head')[0].appendChild(script); // adiciona script no HEAD
}
</script>
  • pśe I used something similar, which is why I need something more geared for him to do this check on Gento, because my script runs even before jQuery was loaded, I tried to use setTimeot etc.. But it works on some pages and on others more "heavy" it error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.