I am trying differents methods to implement a function, but one o them isn’t working.
Are this syntax correct?:
function funcao2()
{
alert('Tudo bem?');
}funcao2();
I have a ‘self invoking function’, an ‘anonymous function’ and a ‘function attributed to a variable’, but the second aren’t working. See the code:
<script type="text/javascript">
//Função de auto-invocação anônima ou função recursiva anônima
(function(){
alert('Oi');
})();
//Função anônima
document.onload = function(){
alert('Página carregada');
};
//Atribuir função a uma variável e executá-la em seguida
var funcao = function(){
alert('Oi novamente');
}; funcao();
Commented this, seems to be what the OP wanted to know, so posting it as an answer:
document.onloadshould bewindow.onload,documenthas theonreadystatechangeevent, thewindowloadsrelated:
when using the
document.onreadystatechangeevent, check the status and readystate properties: