Created
October 21, 2012 16:49
-
-
Save ryan-blunden/3927560 to your computer and use it in GitHub Desktop.
Get Script
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 getScript(src, callback) { | |
var script = document.createElement('script'); | |
script.src = src + '?nc=' + new Date().getTime(); | |
var done = false; | |
script.onload = script.onreadystatechange = function () { | |
if (!done && (!this.readyState | |
|| this.readyState === 'loaded' | |
|| this.readyState === 'complete') | |
) { | |
done = true; | |
callback(); | |
/* Handle memory leak in IE */ | |
script.onload = script.onreadystatechange = null; | |
document.head.removeChild(script); | |
} | |
}; | |
document.head.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment