Created
January 31, 2013 20:01
-
-
Save qmmr/4685913 to your computer and use it in GitHub Desktop.
loadScript function - async
This file contains hidden or 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
var loadScript = function(url, callback) { | |
var s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; | |
if (s.readyState) { // Internet Explorer | |
s.onreadystatechange = function() { | |
if (s.readyState == 'loded' || s.readyState == 'complete') { | |
s.onreadystatechange = null; | |
callback(); | |
} | |
}; | |
} | |
else { // other browsers | |
s.onload = function() { | |
callback(); | |
}; | |
} | |
s.src = url; | |
document.getElementsByTagName('head')[0].appendChild(s); | |
}; | |
loadScript("https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js", function() { | |
alert('jQuery loaded!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment