Created
June 24, 2013 14:27
-
-
Save adrienjoly/5850443 to your computer and use it in GitHub Desktop.
Function to include a javascript file dynamically into a HTML page, with a callback when the script is loaded.
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
function loadJS(src, cb) { | |
var inc = document.createElement("script"); | |
inc.onload = inc.onreadystatechange = function() { | |
if (cb && inc.readyState == "loaded" || inc.readyState == "complete" || inc.readyState == 4) | |
cb(); | |
}; | |
inc.src = src; | |
document.getElementsByTagName("head")[0].appendChild(inc); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment