Solved

Need code for detecting OS?

Posted on 2002-03-19
9
175 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

803 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