2016-07-07 51 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%確定。