-1

I would like to change things on my site depending on the user agent. Specifically I want to change the text and url of a download button so that when a user is on Ubuntu/Linux, Arch/Linux, Debian-based/linux, Mac OS X, or Windows they are are presented with info and a download button that will be reverent to them. Kinda like LibreOffice does.

I would like to do this in JavaScript and not on the server.

Thanks in advance.

Andrew Pullins
  • 452
  • 14
  • 20
  • See [this](https://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript) and [this](https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript). – Sebb Jul 02 '15 at 00:07
  • Bad idea. Are you going to support these operating systems https://en.wikipedia.org/wiki/List_of_operating_systems ? What if the users main operating system is different to that of the VM OS? – jeff Jul 02 '15 at 00:30
  • Jeff we are going to add a link to switch OS like LibreOffice does. – Andrew Pullins Jul 02 '15 at 01:10

2 Answers2

1

You can use a conditional on these variables to apply to appropriate changes to the site's styles or DOM.

Erik Berkun-Drevnig
  • 2,129
  • 19
  • 36
1

Take a look to the navigator.appVersion property:

function isOS(str){
    str = str.toLowerCase()
    var os_ver = navigator.appVersion.toLowerCase().substring(navigator.appVersion.indexOf("(")+1, navigator.appVersion.indexOf(")"))
    return ~os_ver.indexOf(str)
}

This should work. I know it works for windows.

Pierre Tassel
  • 426
  • 3
  • 9