0

i don't understand what the use of windows.onload(), somebody explain me please... thankz.

22nd Sep 2016, 3:42 AM
Daniel Luperdi
Daniel Luperdi - avatar
2 odpowiedzi
+ 5
webpages take time to load, ee have all experienced this. The thing with javascript is that it executes once the script is loaded. Imagine you want javascript to run an animation inside a div, but javascript loads before the div... then your script either has some faulty behaviour, or wonn work at all. So, to solve this, javascript has a simple method which executes once the whole page is loaded. window.onload() { console.log("page loaded completely!") } if we run the code above, once the whole page loads, it will print the string on the console. without the window.onload, it would execute inmediatly, even if the page hasn't fully loaded at the moment.
29th Sep 2016, 12:02 AM
Alejandro Aristizabal
Alejandro Aristizabal - avatar
+ 2
window.onload=function(){ alert(1); } Your code is written in function, and when the entire page is loaded(These include pictures, videos, scripts, and other resources), the output will be 1.
22nd Sep 2016, 7:08 AM
yazhe wang
yazhe wang - avatar