Re: Page refresh throws JavaScript error



On Jul 22, 4:18 pm, pr wrote:
Chris Beall wrote:
<snip>
Also, how did you determine the (varying) value of
document.styleSheets[0].cssRules.length? ...
<snip>
Just the trusty window.alert():

if (document.styleSheets[0].cssRules){
theRules = document.styleSheets[0].cssRules
alert("cssRules " + document.styleSheets[0].cssRules.length);
}

You'll be using that a lot :-)

This is true, but the drawbacks of using - alert - for testing/
reporting/debugging could be mentioned. They can tell you the state at
the point when they open but opening the alert has consequences. It
blocks the execution of the code that opens it, but in doing that
frees to browser to do other things (so race conditions where a script
is racing the browser will be radically altered).

Also, they take the input focus, and so events such as onfocus, onblur
and onchnage may be triggered wherever the focus had been when the -
alert - opened. Making - alerts - problematic when examining
interactions. This problem is quite well illustrated by this page by
John Resig:-

<URL: http://ejohn.org/blog/most-bizarre-ie-quirk >

- where totally bogus conclusions have been drawn as a result of
attempting to examine features of browser/mouse interactions using an
- alert -; Replacing his test code with:-

var count = 0;
setInterval(function(){
window.status = ++count;
}, -1);

- makes an obvious nonsense of all of the conclusions drawn.

Non-blocking reporting that does not take focus used to be commonly
achieved by writing the - window.status - property, which resulted in
the written message appearing in the browser's status bar. Modern
browsers increasingly default to not allowing status bar writing by
scripts, and so need it to be enabled by the user if that technique is
to be used.

However, modern browsers (at least while using an HTML DOM) also allow
writing the innerHTML of elements, giving another easy option for non-
blocking reporting. Though more use while learning and formal testing
than in debugging a 'finished' project (as adding an element to write
into may not be practical or consequence free).
.


Loading