Search code examples
javascriptdomcross-browserdom-events

document.readyState on DOMContentLoaded?


In browsers that support the event DOMContentLoaded and the property document.readyState:

When DOMContentLoaded fires, can I assume that the value of document.readyState will always be either "complete" or "interactive"/"loaded"?

(Or could it be that document.readyState sometimes 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.


Solution

  • 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.