Reputation: 83
When I used window.onload=function_name() where function_name is a java script function, the function did not get executed. But it works fine when I use window.onload=function_name.
Upvotes: 1
Views: 192
Reputation:
window.onload=function_name;
This will be executed as expected when windows loading finished, while this one:
window.onload=function_name();
Will be executed when browser reaches that point and the value for the function will be returned to the window.load after page loaded.
Upvotes: 1
Reputation: 28688
window.onload=function_name()
calls the function function_name
and sets the onload
handler to its return value.
window.onload=function_name
sets the handler to the function itself, so function_name
will be called when the onload
event occurs.
Upvotes: 3