Created
October 10, 2019 19:40
-
-
Save onesmartguy/1e087a682bde70ef8fa1527c82651c6f to your computer and use it in GitHub Desktop.
loadjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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