March 8, 2000 - Detecting Stylesheets | WebReference

March 8, 2000 - Detecting Stylesheets

Yehuda Shiran March 8, 2000
Detecting Stylesheets
Tips: March 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Some applications rely on the existence of stylesheets. For a graceful exit in the case of disabled stylesheets, we need to know if they are enabled or disabled. If the browser is Internet Explorer 4.0x, stylesheets cannot be disabled. However, if the user is running Navigator 4.0x, we must find out if they are disabled by checking the existence of an element. The following code must be inserted before the script:

<SPAN ID="test" STYLE="position: absolute;"></SPAN>

The following variable determines whether or not stylesheets are enabled, by checking the livelihood of the above test id:

var style = ((NS4 && document.test) || IE4) ? 1 : 0;

NS4 is true when the Netscape Navigator version is 4 and up. IE4 is true when the Internet Explorer version is 4 and up as well.

Learn more about the application that uses this technique in Column 16, Dynamic Tooltips.