Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created December 18, 2011 04:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/1492372 to your computer and use it in GitHub Desktop.
Save rlemon/1492372 to your computer and use it in GitHub Desktop.
loadScript :p
function loadScript(url, callback) {
if(!url) {
return;
}
callback = typeof callback == 'undefined' ? function(){} : callback;
var script_elm = document.createElement('script');
script_elm.src = url;
script_elm.onreadystatechange = function() {
if (this.readyState == 'complete') {
callback.call();
}
};
script_elm.onload = callback;
document.getElementsByTagName('head')[0].appendChild(script_elm);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment