Solved

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

Posted on 2002-03-08
8
411 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Accepted Solution

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

Expert Comment

by:ahosang
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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)

744 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

12 Experts available now in Live!

Get 1:1 Help Now