Skip to content

Instantly share code, notes, and snippets.

@adamculpepper
Last active January 11, 2018 22:49
Show Gist options
  • Save adamculpepper/b1a81efb05a89bf0054521c1e19315fc to your computer and use it in GitHub Desktop.
Save adamculpepper/b1a81efb05a89bf0054521c1e19315fc to your computer and use it in GitHub Desktop.
Injects JavaScript file into a page (not jQuery dependent)
// code from Stack Overflow, made into a function
// https://stackoverflow.com/a/10735151
function injectJSFile(fileURL) {
var script = document.createElement('script');
script.src=fileURL;
script.type='text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
}
injectJSFile('../assets/js/local-file.js'); // USAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment