0
Hello, I have the following code
<html>
//=======Teste1========
<script
type="text/javascript"
src="http://modulo.que.sera.carregado.js"
data-token="">
</script>
//=======Teste2========
<script>
scriptTeste = function() {
var dados = JSON.parse(localStorage.dados);
var node = document.createElement("script");
var att = document.createAttribute("data-token");
att.value = dados.token;
node.setAttributeNode(att);
document.getElementById("idBody").prepend(node);
}
scriptTeste();
</script>
</html>
The value of data-token will come by user session, and I need to add it to the script. After loading this initial script should be loaded another Script that depends on the first modules already loaded.
I added in the example above the two codes I tested.
The Teste1 worked only when I left the fixed date-token value. The Teste2 did not work because the second script that will be loaded does not expect this first script to finish loading the modules.
But the first script will depend on the value of the second token?
– Sam
No, the first script depends on the Session token, and the second script depends on the full load of the module the first loads.
– Rodolfo Moreira
Try replacing
scriptTeste();
forwindow.onload = scriptTeste;
.– Sam
Try putting the attribute
defer
andonload="scriptTeste()"
on the tag:<script defer onload="scriptTeste()"...
– Sam
Good morning, that I had tried too. It didn’t work.
– Rodolfo Moreira