I created a function in JavaScript that when executed 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 within that file that has just been loaded is called, but part of the name of that 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();"
, which is in the .js file that just was loaded.
I have tried to use several codes like return "funcao_" + parametro + "();"
and even the so controversial eval
, in fact, I tried anyway and I could not, or Chrome says that the function is not defined or the whole script does not work. Could you please help me? I'm new to JavaScript and I have no idea how to do this.
Note: I'm sure the other JS file is OK, so the problem is not in it.