I need to execute specific JavaScript instructions AFTER an external JavaScript finishes 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 that .js has finished doing what it does?
The $.getScript
method can load script files even from external domains, and you can provide a callback function, that will be executed when if the script is loaded successfully:
$.getScript('http://xxxxxxxx.disqus.com/embed.js', function () {
// specific instructions here...
alert('Script loaded!');
});
Check the above example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With