[Javascript] Questions about document.readyState
Nick Fitzsimons
nick at nickfitz.co.uk
Sun Jun 25 09:43:28 CDT 2006
tedd wrote:
> Oh javascript masters:
>
> I'm trying to figure out "document.readyState" and how it works.
>
> In my quest, I came across a couple of things that don't seem logical to me. Maybe someone here would be knowledge and kind enough to explain it to me.
>
> My questions and example are shown here:
>
> http://xn--ovg.com/a7.php
>
> Why?
>
> tedd
>
> PS: If you browser complains about the url, please let me now -- thanks.
>
Your code is writing to the document (using document.write()) and then
recursively calling itself. The document can never be complete until you
stop writing to it. Also the JavaScript interpreter has a sanity check
which, finding that the function has called itself 1000 times, assumes
that a bug is causing an infinite recursive descent and stops it to
prevent your browser from crashing.
Try something like the following:
var states = [];
function checkReadyState() {
var state = document.readyState;
states.push(state);
if (state == "complete") {
clearInterval(timer);
alert(states.join("\n"));
}
}
var timer = setInterval(checkReadyState, 10);
The Microsoft documentation for readyState is at:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp?frame=true
Note that it's a non-standard property, so non-Microsoft browsers are
under no obligation to support it, or to have it work the same way. The
above code shows different results in Internet Explorer for Windows (v.
6) and Opera (v. 8.5), but shows no result at all in Firefox 1.5.
HTH,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
More information about the Javascript
mailing list