Skip to content

Instantly share code, notes, and snippets.

@onesmartguy
Created October 10, 2019 19:40
Show Gist options
  • Save onesmartguy/1e087a682bde70ef8fa1527c82651c6f to your computer and use it in GitHub Desktop.
Save onesmartguy/1e087a682bde70ef8fa1527c82651c6f to your computer and use it in GitHub Desktop.
loadjs.js
// https://stackoverflow.com/questions/14521108/dynamically-load-js-inside-js
var loadJS = function(url, implementationCode, location){
//url is URL of external file, implementationCode is the code
//to be called from the file, location is the location to
//insert the <script> element
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = implementationCode;
scriptTag.onreadystatechange = implementationCode;
location.appendChild(scriptTag);
};
var yourCodeToBeCalled = function(){
//your code goes here
}
loadJS('yourcode.js', yourCodeToBeCalled, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment