var script=document.createElement('script'); if(script.onreadystatechange){ script.onreadystatechange=function(){ if(this.readyState==='loaded' || this.readyState==='complete'){ script.onreadystatechange=null; callback(); } } }else{ script.onload=function(){ callback(); } } script.setAttribute("src",url); document.body.appendChild(script);