Last active
December 15, 2015 05:39
-
-
Save ziluo/5210469 to your computer and use it in GitHub Desktop.
无阻塞的JS加载模式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function loadScript(url,callback){ | |
var script = document.createElement("script"), | |
script.type = 'text/javascript'; | |
if(script.readyState){ //ie | |
script.onreadystatechange = function(){ | |
if(script.readyState == 'loaded' || script.readyState == 'complete'){ | |
script.onreadystatechange = null; | |
callback(); | |
} | |
} | |
}else{ | |
script.onload = function(){ | |
callback(); | |
}; | |
} | |
script.src = url; | |
document.getElementByTagName('head')(0).appendChild(script); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment