可能重复:
How to find the operating system version using JavaScriptOS和OS版本检测在JavaScript
我怎么可以检测到使用javascrtip其中OS和OS版本,我的客人。例如Windows Vista或七或Xp和Linux也是如此。
可能重复:
How to find the operating system version using JavaScriptOS和OS版本检测在JavaScript
我怎么可以检测到使用javascrtip其中OS和OS版本,我的客人。例如Windows Vista或七或Xp和Linux也是如此。
navigator.platform会为您提供他们正在使用的当前平台,就像navigator.userAgent会为您提供整个浏览器字符串一样。
要检测客户机上的操作系统,您的脚本应该分析navigator.appVersion字符串。以下是一个脚本的简单示例,它将变量OSName设置为反映实际的客户端操作系统。
// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
在系统上,该脚本将产生以下结果: 您的操作系统:Windows
(要获得更详细的系统信息,你的脚本应该执行navigator.appVersion
串的更复杂的分析,但想法将是相同的。)
在Firefox/WinXP上输出navigator.appVersion
。
5.0 (Windows; en-US)
在Firefox/WinXP上输出navigator.userAgent
。
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
的navigator.platform
Win32
请举个例子。了解它对我很重要 – 2011-03-03 16:03:19
输出仅工作在Firefox,而不是镀铬 – gkmohit 2016-08-26 03:02:15