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
Solved

Need code for detecting OS?

Posted on 2002-03-19
9
180 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Create tabs to show divs 9 35
Can't get js include to work in html file 8 20
Show Ruler in Outlook 2010 STILL NOT SHOWING! 4 23
html border input line 7 13
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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