Hello Gentlemen,
My name is kleber and I’m in Brazil.
My OS is windows 10 and I’m working with Edge.
I’m testing a routine to dynamically load a javascript file and
I have the following problem :
- Apparently the script is loaded on first run.
- When trying to execute a function declared in the loaded javascript,
immediately after loading , I see an error message
on the console that the requested function does not exist. - When trying to perform the same function for the second time and using the same process, it runs successfully.
After several changes and unsuccessful attempts , the impression that remains is that the script is loaded on the first run , however , the functions
contained therein are not available for immediate execution.
Does anyone know why it’s not running the first time?
Note - This text was translated by google
function load_javascript(url) {
let myScript = document.createElement(“script”);
myScript.setAttribute(“src”, url);
document.body.appendChild(myScript);
myScript.addEventListener(“load”, scriptLoaded(url), false);
}
function scriptLoaded(url) {
console.log(“Script " + url + " was dynamically loaded!!!”);
}
Thank you for your attention.