views:

73

answers:

1

Hi, 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?

+10  A: 

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.

CMS
hi... the problem is that embed.js execute specific things and that doesn't happen immediately. It takes around 3 seconds for the script to complete its processes, but the alert triggers sooner than that =( -- any ideas?
andufo