问题
In browsers that support the event DOMContentLoaded and the property document.readyState:
When
DOMContentLoadedfires, can I assume that the value ofdocument.readyStatewill always be either"complete"or"interactive"/"loaded"?(Or could it be that
document.readyStatesometimes still has the value"loading"?)
In your answer please provide a reference to an authoritative source.
You may wonder: Why not just listen to readystatechange? It is because the Android 2.3.5 standard browser is a target platform, and it does not implement the readystatechange event.
回答1:
The value of the readyState property is always "interactive" when DOMContentLoaded has fired. This is evidenced by the fact that the MDN documentation claims:
// alternative to DOMContentLoaded event
document.onreadystatechange = function () {
if (document.readyState == "interactive") {
initApplication();
}
}
is interchangeable with a DOMContentLoaded handler. You can also have a look at the spec here, which reiterates this.
来源:https://stackoverflow.com/questions/13346746/document-readystate-on-domcontentloaded