在javascript中的os和os版本检测

A.B*_*per 2 javascript

可能重复:
如何使用JavaScript查找操作系统版本

我如何能够检测到我的访问者在javascrtip中使用哪个os和os版本.例如windows vista或者七或者Xp和linux.

Har*_*OTA 14

要检测客户端计算机上的操作系统,您的脚本应分析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);
Run Code Online (Sandbox Code Playgroud)

在您的系统上,此脚本会产生以下结果:您的操作系统:Windows

(要获得更详细的操作系统信息,您的脚本应该对navigator.appVersion字符串执行更复杂的分析,但想法是相同的.)