+ 1

Body.onload vs window.onload

what is the difference between body. onload and window.onload?

28th Jan 2017, 4:58 AM
Priyan Perera
Priyan Perera - avatar
1 ответ
+ 2
Almost the same... They are fired when all page content is loaded ( including external files as css, js, images... ). The only difference is that body onload could be use inlined in Html ( <body onload="body_load();"> ), and the window onload could be set/used at very begining of a html script ( even in the <head> part, the 'window' object is still available )... With Html5 ( and since IE9 ^^ ) you can use an event fired before, when dom content is ready ( without waiting for external files )... It's also the behaviour of the 'ready()' method in JQuery ( which was supporting cross-browser before Html5/IE9 ): https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded
28th Jan 2017, 6:20 AM
visph
visph - avatar