Solved

Need code for detecting OS?

Posted on 2002-03-19
9
153 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

760 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

17 Experts available now in Live!

Get 1:1 Help Now