views:

129

answers:

5

What's the standard, most reliable way of doing this? I need to redirect a user to download the Mac version or the Windows version of my software when they click "Download" on my website.

+3  A: 

In Javascript:

http://www.quirksmode.org/js/detect.html

No method is perfect, because the user can always spoof the user-agent.

I would recommend that:

1) Auto-redirect to a page with the link, or auto update the link on a page with text saying "Download for Mac" or "Download for Windows", so that the user knows what they are getting before they click.

2) Still give the user the option of downloading the other version, in case your detection does not work in their case, or if they want to download on a remote machine, and transfer it to a different machine later.

Jeff B
+1  A: 

Not 100% reliable, but you can infer much from a user-agent string in the HTTP header.

Mitch Wheat
@Mitch, but the browser can *lie* on the user-agent string, can't it?
Ngu Soon Hui
Given sufficient motivation, a network client can lie about anything. There's nothing intrinsic about a network packet as seen by a server that says 'mac' or 'windows', at least nothing that can't be forged.
Jherico
and the benefit of trying to spoof a website so you get the wrong download would be what, exactly?
DOK
... that's why I explicitly stated it's not "100% reliable"
Mitch Wheat
@Jherico: unless there is key-exchange taking place between client and server, that is true of ANY detection technique.
Mitch Wheat
@DOK, haha, made me laugh. "I demand the wrong download link - I'm gonna edit my user-agent string!"
alex
A: 

You need to use navigator.platform or parse navigator.userAgent. Example.

Max Shawabkeh
+1  A: 

You want to look at the user agent found within the http header.

User Agent

Jack Marchetti
+2  A: 

It is easily spoofed, but you can take a pretty good guess by examing the user agent string. You can do this in JavaScript or your server side language.

Because you may detect it incorrectly, you should place somewhere a "Want the Mac OS X version" etc somewhere.

alex