How do I modify the below code? I would like to load exactly two scripts before adding next code from function yourCodeToBeCalled
. Can someone give a hint for a beginner? I gave my suggestions after comment //.
var loadJS = function(url, implementationCode){//url, url_Next
//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');//will add scriptTag_Next
scriptTag.type = 'text/javascript';
scriptTag.setAttribute('nonce','22os9h3sdfa');
scriptTag.src = url;
scriptTag.onload = implementationCode;//Will It be work? -> scriptTag.onload = scriptTag_Next = implementationCode;
scriptTag.onreadystatechange = implementationCode;//like as above scriptTag_Next.onreadystatechange ??
document.body.appendChild(scriptTag);
};
var yourCodeToBeCalled = function(){
console.log('okay'); } loadJS('js/jquery-3_1_1.min.js', yourCodeToBeCalled);//My my suggestion loadJS('js/jquery-3_1_1.min.js', 'js/test.js' yourCodeToBeCalled)
Original code I borrowed from: link