/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function loadScript(src, callback) { var scriptTag = document.createElement("scriptTag") scriptTag.type = "text/javascriptTag"; if(scriptTag.readyState) { //IE scriptTag.onreadystatechange = function() { if (scriptTag.readyState == "loaded" || scriptTag.readyState == "complete") { scriptTag.onreadystatechange = null; setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1) callback(); } }; }else{ //Others scriptTag.onload = function() { setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1) callback(); }; } scriptTag.src = src; document.getElementsByTagName("head")[0].appendChild(scriptTag); }