Skip to content

Instantly share code, notes, and snippets.

@matijs
Created March 9, 2016 18:37
Show Gist options
  • Select an option

  • Save matijs/3bf8703a773b8b6a6ed0 to your computer and use it in GitHub Desktop.

Select an option

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

matijs commented Mar 9, 2016

Copy link
Copy Markdown
Author

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