Skip to content

Instantly share code, notes, and snippets.

@matijs
Created March 9, 2016 18:37
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 matijs/3bf8703a773b8b6a6ed0 to your computer and use it in GitHub Desktop.
Save matijs/3bf8703a773b8b6a6ed0 to your computer and use it in GitHub Desktop.
Sure fire DOM Element insertion
function insertScript(url, onload, onerror) {
var ref = document.getElementsByTagName('script')[0];
var script = document.createElement('script');
script.src = url;
if (typeof onload === 'function') {
script.onload = onload;
}
if (typeof onerror === 'function') {
script.onerror = onerror;
}
ref.parentNode.insertBefore(script, ref);
}
@matijs
Copy link
Author

matijs commented Mar 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment