Skip to content

Instantly share code, notes, and snippets.

@moalex
Last active December 17, 2015 05:38
Show Gist options
  • Save moalex/5558783 to your computer and use it in GitHub Desktop.
Save moalex/5558783 to your computer and use it in GitHub Desktop.
more or less stolen form jquery core and adapted by paul irish ### usage: getScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js',function(){ alert('jQuery loaded. yay life') });
function getScript(url,success){
var head = document.getElementsByTagName("head")[0], done = false;
var script = document.createElement("script");
script.src = url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
success();
}
};
head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment