Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need code for detecting OS?

Posted on 2002-03-19
9
Medium Priority
?
194 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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.
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…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

670 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