1

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.