网站如何确定操作系统版本?

时间:2016-12-07 10:35:33

标签: javascript html web

如何编写网站,确定用户是否使用服务器版Windows浏览?

示例:

  • 如果用户使用Windows Server 2016 => Server
  • 如果用户使用Windows 10 => not Server

2 个答案:

答案 0 :(得分:1)

您可以使用navigator.userAgent返回包含各种信息的字符串,例如在我的机器上:

"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"

那么我们就可以做到:

function getOS() {
    if (navigator.userAgent.includes('NT 10.0')) {
        return 'Win10';
    } else if (navigator.userAgent.includes('NT 8.1')) {
        return 'Win8.1';
    }
    //etc...
}

答案 1 :(得分:0)

使用javascript可以轻松完成。请参阅以下链接: Can I use JavaScript to detect the operating system on the client machine

使用java你可以使用System.getProperty("os.name"),但是这不会影响你的目的,因为这将为你提供运行java的操作系统,这将是服务器的操作系统

我刚发现这个我认为它解决了你的问题:

How can I get client infomation such as OS and browser