[thelist] Platform Detection and CSS

Blake Coglianese blake at focusednrg.com
Mon Jun 24 19:49:02 CDT 2002


Hi all,

I am trying to create a JavaScript that detects the browser and os. I then
want the JavaScript to write the linked style sheet. It is working on Mac in
both IE and Netscape but I cannot get it to work on a windows machine. Im
not much of a JavaScript programmer so any help would be appreciated. The
script I am using is below.

<script language="JavaScript" type="text/JavaScript">

 if(navigator.userAgent.indexOf('Mac') != -1 &&
navigator.appName.indexOf("Netscape")>(-1))
{
 document.write('<link rel=stylesheet href="css/wsNetscapeMac.css"
type="text/css">')
}
 else if(navigator.userAgent.indexOf('Mac') != -1 &&
navigator.appName.indexOf("Explorer")>(-1))
{
 document.write('<link rel=stylesheet href="css/wsIEMac.css"
type="text/css">')
}
 else if(navigator.userAgent.indexOf('win') != -1 &&
navigator.appName.indexOf("Netscape")>(-1))
{
 document.write('<link rel=stylesheet href="css/wsNetscapeMWin.css"
type="text/css">')
}
 else (navigator.userAgent.indexOf('win') != -1 &&
navigator.appName.indexOf("Explorer")>(-1))
{
 document.write('<link rel=stylesheet href="css/wsIEMWin.css"
type="text/css">')
}
</script>

TIA,

Blake
blake at focusednrg.com




More information about the thelist mailing list