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.
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.
Not 100% reliable, but you can infer much from a user-agent string in the HTTP header.
You need to use navigator.platform
or parse navigator.userAgent
. Example.
You want to look at the user agent found within the http header.
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.