Link to home
Start Free TrialLog in
Avatar of drstuey
drstuey

asked on

OS detection script for CSS link tag - is this correct syntax?

a quickie for who ever gets it first:

Is this the correct syntax for conditionally including a link to a mac and PC stylesheet.

<SCRIPT LANGUAGE="JavaScript">
<!--
version = navigator.appVersion;
if (version.toLowerCase().indexOf("mac")!=-1) {
document.write('<link rel="STYLESHEET" type="text/css" href="/styles_mac.css">');
}
else {
document.write('<link rel="STYLESHEET" type="text/css" href="/styles.css">');
}
// -->
</script>
Avatar of b1xml2
b1xml2
Flag of Australia image

if (navigator.userAgent.match(/Mac/i)) {
 document.write('<link rel="STYLESHEET" type="text/css" href="/styles_mac.css">');
} else {
 document.write('<link rel="STYLESHEET" type="text/css" href="/styles.css">');

}
Avatar of drstuey
drstuey

ASKER

Thanks, I have implemented that, but I won't know if that worked until I run it through Browser Photo tommorrow.

I was hoping for an explanation as well. I was quite happy with the OS detection part of the script, the explanation I read for doing it this way:

version = navigator.appVersion;
if (version.toLowerCase().indexOf("mac")!=-1)

seemed entirely reasonable to me. It was as much the syntax of everything else I was concerned about. The version I posted doesn't seem to be doing anything, it seems like both CSS links are visible to all browsers so the Macs see the PC CSS link as well and that overrides the Mac one????
it is the wrong property that you are using, to get the Mac platform, it would be safer to use the userAgent property.
Avatar of drstuey

ASKER

Thanks, I have implemented that, but I won't know if that worked until I run it through Browser Photo tommorrow.

I was hoping for an explanation as well. I was quite happy with the OS detection part of the script, the explanation I read for doing it this way:

version = navigator.appVersion;
if (version.toLowerCase().indexOf("mac")!=-1)

seemed entirely reasonable to me. It was as much the syntax of everything else I was concerned about. The version I posted doesn't seem to be doing anything, it seems like both CSS links are visible to all browsers so the Macs see the PC CSS link as well and that overrides the Mac one????
Avatar of drstuey

ASKER

ooops, I must have gone back in my browser and reposted my comment
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to b1xml2
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
Avatar of drstuey

ASKER

Naughty me I have been prompted to give the points out.

Yes it works. It was my mistake that I thought it didn't.

cheers