javascript中的操作系统和操作系统版本检测
可能重复:javascript中的操作系统和操作系统版本检测,javascript,Javascript,可能重复: 如何在javascrtip中检测我的访问者使用哪个操作系统和操作系统版本。例如WindowsVista或seven或Xp和linux navigator.platform将为您提供他们正在使用的当前平台,就像navigator.userAgent将为您提供整个浏览器字符串一样。要检测客户端计算机上的操作系统,您的脚本应分析navigator.appVersion字符串。下面是一个简单的脚本示例,该脚本设置变量OSName以反映实际的客户端操作系统 // This script se
如何在javascrtip中检测我的访问者使用哪个操作系统和操作系统版本。例如WindowsVista或seven或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)
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
Firefox/WinXP上的navigator.userAgent
输出
5.0 (Windows; en-US)
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
请举个例子。了解这一点对我来说很重要,因为我只在FIrefox上工作,不在chrome上工作