Solved

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

Posted on 2002-03-08
8
412 Views
Last Modified: 2013-11-19
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>
0
Comment
Question by:drstuey
  • 4
  • 3
8 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 6852403
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">');

}
0
 

Author Comment

by:drstuey
ID: 6852474
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????
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6852485
it is the wrong property that you are using, to get the Mac platform, it would be safer to use the userAgent property.
0
 

Author Comment

by:drstuey
ID: 6852591
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????
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:drstuey
ID: 6852593
ooops, I must have gone back in my browser and reposted my comment
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 77 total points
ID: 6855298
drstuey, has it been successful?
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8076107
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
0
 

Author Comment

by:drstuey
ID: 8077068
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now