Skip to content

Instantly share code, notes, and snippets.

@moocss
Created July 24, 2014 15:55
Show Gist options
  • Select an option

  • Save moocss/1814089537c47152aa6c to your computer and use it in GitHub Desktop.

Select an option

Save moocss/1814089537c47152aa6c to your computer and use it in GitHub Desktop.
loadScript
function loadScript(url, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
// IE
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // others
script.onload = function () {
callback();
};
}
script.src = url;
document.body.appendChild(script);
}
loadScript("http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", function () {
alert('loaded');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment