Skip to content
Advertisement

Function call after body.onload returns unwanted result

I have the following problem:

JavaScript

This script gives me the desired result: 1 However, the script is executed in my code only with document.body.onload:

JavaScript

But in this case the result is not 1, but [object Event]. What do I have to do to get 1 as result?

Advertisement

Answer

I’m not sure if this is what you mean:

JavaScript

Basically, if you set onload as you function which takes a parameter – the argument will be event itself, not the value you tried to provide to it

You can read more here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement