Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)
What is the difference between window onload and onload on body tag? When do I use them?

1 Answer

0 votes
by (13.1k points)
edited by

In an onload function, the contents of it ran after the object that is calling is fully loaded.

In a window onload function, the contents of the method are only accessible or can be run only after all the DOM, images, etc. of the window are loaded and it applies to the whole window which may take some time to load. It is used when you want the javascript to fire only after all the contents of the window are loaded.

In a body onload function, the contents of the method are accessible or ran after the contents of the body tag are loaded. Compared to the window onload function it takes less time to be fired. It is used when you want the javascript to fire only after all the contents of the body tag are loaded

Check out Web Development training and enroll today!

Related questions

0 votes
1 answer
asked Mar 1, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

Browse Categories

...