[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2002-03-08
8
Medium Priority
?
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 231 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

649 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