0
i don't understand what the use of windows.onload(), somebody explain me please... thankz.
2 Answers
+ 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.
+ 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.