-1

How to write a website, that determines, if the user browses using a Server version of Windows?

Example:

  • If the user uses Windows Server 2016 => Server
  • If the user uses Windows 10 => not Server
MD XF
  • 7,062
  • 7
  • 34
  • 64
Banck
  • 93
  • 9

2 Answers2

1

You can use navigator.userAgent which will return a string containing various pieces of information, for example on my machine:

"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36"

So then we can do:

function getOS() {
    if (navigator.userAgent.includes('NT 10.0')) {
        return 'Win10';
    } else if (navigator.userAgent.includes('NT 8.1')) {
        return 'Win8.1';
    }
    //etc...
}
Jack
  • 774
  • 6
  • 18
  • You can't rely on this. You can change it. – Reinstate Monica Cellio Dec 07 '16 at 10:44
  • but my question: Can I detect if it's Windows server version, or not?) – Banck Dec 07 '16 at 10:45
  • Open a Javascript console in a browser on the server machine and type `navigator.userAgent`, give me the output and I'll update my answer. – Jack Dec 07 '16 at 10:47
  • "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36" – Banck Dec 07 '16 at 10:50
  • @user3006028 that's the Win10 string. As I say I don't know the Windows Server 2016 user agent and Google isn't proving fruitful, but I've updated my answer for win10/8.1. If you can get the user agent for 2016 then I can help you figure out what the conditional should be. – Jack Dec 07 '16 at 11:01
  • Remember includes isn't supported by IE. So it's not super useful for detecting IE. :) You can use a polyfill, but feature detection is preferred over browser detection. – mccambridge Jun 01 '18 at 15:11
0

Using javascript this can be easily done. See the following link: Can I use JavaScript to detect the operating system on the client machine

Using java you could use System.getProperty("os.name") but this does not server your purpose since this will give you the operating system at which java is running which would be the OS of the server

I just found out this one which I think it solves your problem:

How can I get client infomation such as OS and browser

Community
  • 1
  • 1
giannisapi
  • 1,921
  • 2
  • 20
  • 31