JQuery: how do I know when external JS ended?

I need to execute certain javascript instructions AFTER external javascript completes its own process.

(function(){ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://xxxxxxxx.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); 

How can jQuery know when this .js has finished doing what it does?

+4
source share
1 answer

The $.getScript method can load script files even from external domains , and you can provide a callback function that will be executed if the script loads successfully:

 $.getScript('http://xxxxxxxx.disqus.com/embed.js', function () { // specific instructions here... alert('Script loaded!'); }); 

Check out the above example here .

+11
source

Source: https://habr.com/ru/post/1310574/


All Articles