Solved

Need code for detecting OS?

Posted on 2002-03-19
9
193 Views
Last Modified: 2010-04-09
Hi everyone,

I am wondering if there's any code for detecting an operating system that the user is using?  Let's say if a user goes to a specific webpage I want it to detect his OS and then depending if it's Windows or Mac to redirect him to another appropriate page. Is that possible? If yes, please help me out with the script.  I really appreciate it.

--
cyberspy.
0
Comment
Question by:cyberspy
[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
  • 2
9 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 6881752
<script language="javascript">

//general redirection
function redirectPage(szWinURL,szMacURL) {
 if (navigator.userAgent.match(/Mac/i)) {
   if (szMacURL.length != 0) window.location.replace(szMacURL);
 } else {
   if (szWinURL.length != 0) window.location.replace(szWinURL);
 }

}

//e.g. of redirecting if Macs are found
redirectPage("","mac.html");
//e.g. of redirecting if window is found (default)
redirectPage("win.html","");
//e.g. redirecting
redirectPage("index_win.html","index_mac.html");

</script>
0
 
LVL 1

Author Comment

by:cyberspy
ID: 6881766
Thanks for your reply.  Only one question, what is the difference between mac.html and index_mac.html?
You explained in e.g. parts of redirecting for Mac and windows and then just redirecting? please explain me the last one.  Thanks.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6881769
the last one guarantees a redirection, either to the page for Macs or Windows. The function provided is flexible enuff for that.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 1

Author Comment

by:cyberspy
ID: 6881787
Ok, I just tried it and it didn't work.  I place this code in my index.html page and specified index.html for windows redirect and mindex.html for mac redirect and it didn't work.  I'm not sure why...?
0
 
LVL 18

Expert Comment

by:bruno
ID: 6881790
the code Brandon provided was client side, i can offer a server side function if you support ASP?

BRUNO
0
 
LVL 1

Author Comment

by:cyberspy
ID: 6881806
No, client side is fine, but it didn't work when I opened the page on Mac, it stayed on the index.html page.  How can I get it to work? Please help me out.
0
 
LVL 18

Accepted Solution

by:
bruno earned 100 total points
ID: 6881818
try this....





<script language="javascript">

if ((navigator.appVersion.indexOf("Mac") != -1))
{
window.location = 'your_mac_page.html'
}


</script>




BRUNO
0
 
LVL 1

Author Comment

by:cyberspy
ID: 6881841
That worked just fine, Thanks BRUNO:)!!
0
 
LVL 18

Expert Comment

by:bruno
ID: 6881860
Glad I could help!  Thanks for the A.  :-)
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

624 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