views:

126

answers:

4

What is the most reliable way to determine the OS of a visitor to a web site? All other things being equal I prefer an easier to integrate solution. I'm not attempting to gather analytics and I understand there is no completely reliable method. The purpose of this is to subtlely tailor the user experience in ways that do not affect the functionality of the site -- for instance, making a guess at which os version of a cross platform app the user would like to download (I won't hide the other selections, the one matching the user's OS will just become more prominent).

+2  A: 

There is no reliable way to do it, and it's not only none of your business, it's also something your web site should pay no attention to.


If this was something your site was meant to know, then there would be a navigator.os property. Note there is not.

John Saunders
While I agree for the most part, it is useful for analytics/statistic tracking.
jason
@Downvoter: chime in. Be specific. You must have more to say than just, "-1".
John Saunders
@jason: it's only useful if it's accurate. Otherwise, it's useful for fools addicted to numbers, to make them think they know something.
John Saunders
P.S. it was not I that downvoted.
jason
@John: "fools addicted to numbers" == most corporate clients
jason
@jason: no problem. One just learns little from "-1". It's why we progressed from exit codes with 0 or -1 up to actual exceptions.
John Saunders
@jason: I agree. That's who I meant, btw, not you.
John Saunders
Not downvoting, but I'm curious as to why you feel it is none of the site owners business? Is there no possible scenario where content tailored to visitors OS could improve their experience?
Tom
If the visitors want the improved content, then ask them what OS they're using, and I'm sure they'll tell you. You can ask them all sorts of things that would questionable if you tried to guess them or otherwise take the information unasked.
John Saunders
Its not something where the site will completely change, I just want to use a best guess to try and reduce effort. If its wrong its not the end of the world. Why is this particular set of information "none of my business"?
Luke
To be clear, this isn't being used for analytics.
Luke
It's not the only thing that may be none of your business If you want the information, why not ask for it? At least, why not tell the users, clearly, what information about them you're using without asking for it? If you think they might not choose to give you the information, but you're going to use it anyway, well, then I think there's a valid ethical question there.
John Saunders
Implicit in the use of a javascript engine is the ability to report some details of your environment to any sites you visit. Implicit in sending a user-agent string is your sharing of what is in there. Any of these can be disabled, and are far from personal details IMO.
Luke
I have no idea why you feel the OS is implicit in the user-agent. Why is there no separate property for it? And, again, why not _ask_? You seem to feel that you have to hide the fact that you want to know.
John Saunders
+6  A: 

On the client side, you can use Javascript to try to detect it:

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

Sourced from here. Javascript methods are inherently unreliable however. Server side, you can examine some of the HTTP headers in the language of your choice, however, these can also be crafted and are unreliable as well.

In short, there's no 100% reliable method.

zombat
Not looking for 100% reliable, just most reliable.
Luke
+1  A: 

Here are examples of Perl code that does OS detection server-side from useragent strings:

Anirvan
+1  A: 

What is the most reliable way to determine the OS of a visitor to a web site? Ask them on a survey... all else is a crap shoot. Using the UserAgent string you may be able to divine the OS, but as numerous articles will attest - there is no really reliable way to tell.

AnonJr