|
|
JavaScripts :: Detectors :: StyleSheet Loader
Most CSS syntax is understood by most browsers. However, when coding for Netscape 4, you must use CSS syntax strictly as specified in the Standards Specifications. Of course, some browsers (such as Internet Explorer) have extended the attributes, classes and pseudo classes available to you, the coder. There are many tricks that can be used while coding to ensure one stylesheet can be used for all browsers. Sometimes, we just just don't have the time to apply or learn of those tricks. The script allows you to take the easy way out.
This javascript will read which browser is calling the external style sheet, and point the browser to css file specified. If want to use one CSS external stylesheet for IE and one for NS, this script can detect the browser and link to the correct CSS file. If you need to detect other browsers, please see our Browser Sniffer javascript. Copy and paste the code between the <head> and </head> tags.
The Script
<script>
<!--
/* Copyright http://www.perlscriptsjavascripts.com
Free and commercial Perl and JavaScripts */
isNN = document.layers ? 1 : 0;
if(isNN) {
document.write("<link rel=stylesheet href=\"NNstyles.css\">")
} else {
document.write("<link rel=stylesheet href=\"IEstyles.css\">")
}
// -->
</script>
Note
When nesting quotes (quotes inside quotes), you must escape the inner quotes. As is done with this script. Make sure you also add the correct path to your external style sheets. You may choose to add an absolute path. Eg.
document.write("<link rel=stylesheet href=\"http://www.yourserver.com/IEstyles.css\">")
|
|
|