You can also achieve this with a callback:
var addScript=function(filename,callback){
var e=document.createElement('script');
e.type = 'text/javascript';
e.src = filename;
if(callback){
e.onloadDone=false;
e.onload=function(){e.onloadDone=true;callback();};
e.onReadystatechange=function(){
if(e.readyState==='loaded'&& !e.onloadDone){
e.onloadDone=true;callback();
}
}
}
if(typeof(e)!=='undefined'){
document.getElementsByTagName('head')[0].appendChild(e);
}
}
addScript('http://yoursite.com/js/yourScript.js',function(){functionFromYourScript();});
(of course, you will want to optimize this to insert it into the bookmarklet, but you will get the idea ...)
source
share