Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created February 24, 2011 23:40
Show Gist options
  • Select an option

  • Save johnpena/843147 to your computer and use it in GitHub Desktop.

Select an option

Save johnpena/843147 to your computer and use it in GitHub Desktop.
Dynamically load a javascript file
function loadScript(src, callback) {
var head = document.getElementsByTagName('head')[0];
var new_script = document.createElement('script');
new_script.type = 'text/javascript';
new_script.src = src;
// most browsers
new_script.onload = callback;
// IE 6 & 7
new_script.onreadystatechange = function() {
if (this.readyState == 'complete') {
callback();
}
};
head.appendChild(new_script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment