0
The estate
window.onload () = () => {
//Executa algo
}
Can it only be in a script? Let me give an example for the best understanding.
If I have 3 scripts called:
mail js.
js test.
something.js
and the three (separately) I put:
mail js.
window.onload () = () => {
//Função de mail.js
alert("Teste 1");
}
js test.
window.onload () = () => {
//Função de teste.js
alert("Teste 2");
}
something.js
window.onload () = () => {
//Função de algo.js
alert("Teste 3");
}
when I load my html and put:
<!Doctype HTML>
<html>
<head>
<script src="mail.js">
<script src="teste.js">
<script src="algo.js">
</head>
<body></body>
</html>
Will all scripts be executed even if the property is repeated? I am asking this question because my real example may be giving this and not running the others (runs only the first, and the other two are left out).
PS: If the understanding of this question is not enlightening enough I will try to modify it so that it can be clearer.
I’m not sure, but every time you do
window.onload = alugmaFuncao()
it fails to perform for the previous ones, in which case the recommended would be to usewindow.addEventListener('load', funcao)
– Denis Rudnei de Souza
I did some tests and that’s right, I still find a good reference explaining the reason, but briefly is why there can only be a function in the
window.onload
, when calling again with another function the previous one is replaced, theaddEventListener
doesn’t have that problem– Denis Rudnei de Souza
Wow, that is weird. Thanks for answering, but I still wonder... if I don’t use this function in my scripts it doesn’t run, if I use something as constants and variables doing a validation in mail.js and test.js and using something like validating another form, I wouldn’t run either of the two.
– Devprogramacao