Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Created March 25, 2015 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pointofpresence/802f7743ebd9beec0b70 to your computer and use it in GitHub Desktop.
Save pointofpresence/802f7743ebd9beec0b70 to your computer and use it in GitHub Desktop.
function loadScript(url, callback)
{
// Adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
// Fire the loading
head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment