[thelist] Javascript - Browser detection
Zoe Oughton
zoe.oughton at btconnect.com
Mon Nov 20 02:27:01 CST 2000
Hi Listees
I have a JavaScript which detects the users browser and incorporates
different style sheets depending on the browser.
The four different style sheets I have at the moment are for:
Windows: Internet Explorer
Windows: Netscape
Mac: Internet Explorer
Mac: Netscape
This has been fine so far, however with the new browsers, IE 5 and Netscape
6, I feel that I now need at least 2 other options for the Mac:
Mac: Internet Explorer 5 and above
Mac: Netscape 6 and above
and possibly:
Windows: Netscapte 6 and above.
By adding these extra options will provide me with more control, but I am
not sure how to add this extra detection into the JavaScript I use at the
moment. Are there any JavaScript Guru's who could help me add a small bit
of code for this extra detection.
The script I use at the moment is:
<script type="text/javascript"><!--
if (parseInt(navigator.appVersion) >= 4) {
var IE4 = (navigator.appVersion.indexOf("MSIE") > 0);
var NN4 = (navigator.appName == "Netscape");
var OS;
if (navigator.appVersion.indexOf("Win") > 0) OS = "Windows";
if (navigator.appVersion.indexOf("Mac") > 0) {OS = "MacOS";}
switch (OS) {
case "Windows":
if (IE4 > 0) document.write ("<LINK href='ie.css'
rel='stylesheet' type='text/css'");
if (NN4 > 0) document.write ("<LINK href='nn.css'
rel='stylesheet' type='text/css'");
break;
case "MacOS":
if (IE4 > 0) document.write ("<LINK href='iemac.css'
rel='stylesheet' type='text/css'");
if (NN4 > 0) document.write ("<LINK href='nnmac.css'
rel='stylesheet' type='text/css'");
break;
}
}
//-->
</script>
TIA for any help
Zoe
More information about the thelist
mailing list