I have a website for an application I've developed, which is compiled for a variety of operating systems. On the downloads page, I would like to have it arranged so that the download link for the user's OS is at the top with a big obvious "Download!" button, with the other options listed below in plainer links. How can I do this?
Asked
Active
Viewed 59 times
0
-
Look into `navigator.userAgent` and the `User-Agent` header. – tcooc Aug 12 '14 at 23:08
-
1possible duplicate of [Browser detection in JavaScript?](http://stackoverflow.com/questions/2400935/browser-detection-in-javascript) – SeinopSys Aug 12 '14 at 23:09
2 Answers
1
When you log window
in Mozilla's developer console you can see all the properties of window
, this is quite useful and fun to find new things.
When I did so there is a property called navigator
, and within that platform
.
So, since I was running Linux when I did this, the value of window.navigator.platform
was equal to "Linux"
.
One easy way you could do this is:
document.getElementById("download_btn").setAttribute("href","downloads/package_" + window.navigator.platform + ".zip");
So, if I were to download it off your site, I would download the file "package_Linux.zip".
0
Type navigator
in your javascript console and check out all the goodies you have access to. In particular, userAgent
and platform
.
Combine that with some regex matches and the help of user agent strings list and you're good to go.

elzi
- 5,442
- 7
- 37
- 61