2016-07-07 52 views

回答

19

我学到了很多关于window.navigator对象及其属性:platform,appVersionuserAgent。在我看来,几乎不可能100%确定地检测用户的操作系统,但在我的情况下,85%-90%对我来说已经足够了。

所以,检查万吨stackoverflows的答案和一些文章后,我写了这样的事情:

灵感:

  1. What is the list of possible values for navigator.platform as of today?
  2. Best way to detect Mac OS X or Windows computers with JavaScript or jQuery
  3. How to detect my browser version and operating system using JavaScript?
  4. How to detect Browser and Operating System Name and Version using javaScript

而且我用的移动和桌面浏览器的列表来测试我的代码:

  1. List of all Mobile Browsers
  2. List of all Browsers

此代码工作正常。我在所有操作系统上测试过它:MacOS,iOS,Android,Windows和UNIX,但我无法保证100%确定。