Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When document.readystate==complete is that the same when onload fires?

In Internet Explorer, when onreadystatechange is fired, and readystate switches to complete, is that the same time onload event triggers? Have all the requests completed by this time?

like image 341
GeorgeU Avatar asked Jan 27 '11 14:01

GeorgeU


People also ask

What does document readyState mean?

The readyState of a document can be one of following: loading. The document is still loading. interactive. The document has finished loading and the document has been parsed but sub-resources such as scripts, images, stylesheets and frames are still loading.


2 Answers

document.onreadystatechange is typically more optimal than window.onload as it fires before all external resources such as images are loaded. However, it's not well supported at the moment (but if you're only concerned with IE, then it's not a problem).

See: https://developer.mozilla.org/en/DOM/document.onreadystatechange

Or, for IE: http://msdn.microsoft.com/en-us/library/ms536957(v=vs.85).aspx

like image 173
David Tang Avatar answered Sep 28 '22 06:09

David Tang


document.readyState is a property and window.onload is an event

http://www.w3schools.com/jsref/prop_doc_readystate.asp

http://www.w3schools.com/js/js_events.asp

like image 34
Kris Ivanov Avatar answered Sep 28 '22 06:09

Kris Ivanov