Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Created September 11, 2014 10:02
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 dreamyguy/f198dacda6713f8009fd to your computer and use it in GitHub Desktop.
Save dreamyguy/f198dacda6713f8009fd to your computer and use it in GitHub Desktop.
Inject script tag into body, with callback
// this takes into consideration IE7+
// http://msdn.microsoft.com/en-us/library/hh180173%28v=vs.85%29.aspx
function injectjs(url) {
injs = document.createElement('script');
injs.src = url;
injs.type = 'text/javascript';
injs.async = true;
if(injs.addEventListener) {
injs.addEventListener('load', callback, false);
}
// IE7 & IE8
else if(injs.readyState) {
injs.onreadystatechange = callback;
}
document.body.appendChild(injs);
function callback() {
// script was injected
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment