5
I created a Javascript function that when run creates a tag <script>
in <head>
that loads an external Javascript file.
I want to make sure that after this tag is created, a second function located inside this file that has just been loaded is called, but part of the name of this second function is the parameter of the first function. Here is an example:
I start by creating the tag <script>
:
function funcao_um (parametro) { var script = document.createElement('script'); script.src = 'nomeDoArquivo.js'; document.getElementsByTagName('head')[0].appendChild(script);
Now that it is created, within that same function I want to call another function called "funcao_parametro();"
, that is in the . js file that has just been loaded.
I’ve tried using several codes like return "funcao_" + parametro + "();"
and even the so controversial eval
, Anyway, I tried anyway and I couldn’t, or Chrome says the function is not set or the entire script doesn’t work. Could you help me please? I’m new to Javascript and have no idea how to do this.
Note: I’m sure the other JS file is OK, so the problem is not in it.
I think the
eval
did not work because it is trying to invoke the function without waiting for js loading.– bfavaretto