+ 12
document. onload
Why the javascript code doesn't run on just loading of a document object.(...document.onload)..even if all the HTML,css elements,attributes,properties are loaded.Why we use windows.onload instead?
1 ответ
+ 3
Heres what Lorenz Lo Sauer said:
"The general idea is that window.onload fires when the document's window is ready for presentation and document.onload fires when the DOM tree (built from the markup code within the document) is completed."
"Ideally, subscribing to DOM-tree events, allows offscreen-manipulations through Javascript, incurring almost no CPU load."
"Contrarily, window.onload can take a while to fire, when multiple external resources have yet to be requested, parsed and loaded"
Retrieved from:
https://stackoverflow.com/questions/588040/window-onload-vs-document-onload