使用JS检测MacOS,iOS,Windows,Android和Linux操作系统
问题描述:
如何使用JavaScript检测MacOS X,iOS,Windows,Android和Linux操作系统?使用JS检测MacOS,iOS,Windows,Android和Linux操作系统
答
我学到了很多关于window.navigator
对象及其属性:platform
,appVersion
和userAgent
。在我看来,几乎不可能100%确定地检测用户的操作系统,但在我的情况下,85%-90%对我来说已经足够了。
所以,检查万吨*s的答案和一些文章后,我写了这样的事情:
灵感:
- What is the list of possible values for navigator.platform as of today?
- Best way to detect Mac OS X or Windows computers with JavaScript or jQuery
- How to detect my browser version and operating system using JavaScript?
- How to detect Browser and Operating System Name and Version using javaScript
而且我用的移动和桌面浏览器的列表来测试我的代码:
此代码工作正常。我在所有操作系统上测试过它:MacOS,iOS,Android,Windows和UNIX,但我无法保证100%确定。