首页 > 代码库 > js获取客户端操作系统

js获取客户端操作系统

function detectOS() {

    var sUserAgent = navigator.userAgent;

    var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");

    var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");

    if (isMac) return "Mac";

    var isUnix = (navigator.platform == "X11") && !isWin && !isMac;

    if (isUnix) return "Unix";

    var isLinux = (String(navigator.platform).indexOf("Linux") > -1);

    if (isLinux) return "Linux";

    if (isWin) {

        var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;

        if (isWin2K) return "Win2000";

        var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;

        if (isWinXP) return "WinXP";

        var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;

        if (isWin2003) return "Win2003";

        var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;

        if (isWinVista) return "WinVista";

        var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;

        if (isWin7) return "Win7";

    }

    return "other";

}

 

document.writeln("您的操作系统是:" + detectOS());

 

 

浏览器版信息是可以通过javascript得到的
浏览器代码名称:navigator.appCodeName
浏览器名称:navigator.appName
浏览器版本号:navigator.appVersion
是否支持Java:navigator.javaEnabled()
MIME类型数:navigator.mimeTypes.length
操作系统平台:navigator.platform
插件数:navigator.plugins.length
用户代理:navigator.userAgent
 
EX:
<html>
<head>
<title>JS完整获取IE浏览器信息</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="435" border="1" cellspacing="3" cellpadding="0">
  <tr>
    <td>浏览器类型</td>
    <td> 
      <script>document.write(navigator.appName)</script>
    </td>
  </tr>
  <tr>
    <td >浏览器版本</td>
    <td > 
      <script>document.write(navigator.appVersion)</script>
    </td>
  </tr>
  <tr>
    <td>浏览器语言</td>
    <td> 
      <script>document.write(navigator.browserLanguage)</script>
    </td>
  </tr>
  <tr>
    <td >CPU类型</td>
    <td > 
      <script>document.write(navigator.cpuClass)</script>
    </td>
  </tr>
  <tr>
    <td>操作系统</td>
    <td> 
      <script>document.write(navigator.platform)</script>
    </td>
  </tr>
  <tr>
    <td >系统语言</td>
    <td > 
      <script>document.write(navigator.systemLanguage)</script>
    </td>
  </tr>
  <tr>
    <td>用户语言;</td>
    <td> 
      <script>document.write(navigator.userLanguage)</script>
    </td>
  </tr>
  <tr>
    <td >在线情况</td>
    <td > 
      <script>document.write(navigator.onLine)</script>
    </td>
  </tr>
  <tr>
    <td>屏幕分辨率</td>
    <td>      <script>document.write(window.screen.width+"x"+window.screen.height)</script></td>
  </tr>
  <tr>
    <td>颜色</td>
    <td> <script>document.write(window.screen.colorDepth+"位")</script></td>
  </tr>
  <tr>
    <td>字体平滑</td>
    <td><script>document.write(window.screen.fontSmoothingEnabled)</script></td>
  </tr>
  <tr>
    <td>appMinorVersion</td>
    <td> 
      <script>document.write(navigator.appMinorVersion)</script>
    </td>
  </tr>
  <tr>
    <td >appCodeName</td>
    <td > 
      <script>document.write(navigator.appCodeName)</script>
    </td>
  </tr>
  <tr>
    <td>cookieEnabled</td>
    <td> 
      <script>document.write(navigator.cookieEnabled)</script>
    </td>
  </tr>
  <tr>
    <td >userAgent</td>
    <td > 
      <script>document.write(navigator.userAgent)</script>
    </td>
  </tr>
  <tr>
    <td>javaEnabled</td>
    <td> 
      <script>document.write(navigator.javaEnabled())</script>
    </td>
  </tr>
  <tr>
    <td >taintEnabled</td>
    <td > 
      <script>document.write(navigator.taintEnabled())</script>
    </td>
  </tr>
</table>
</body>
</html>

js获取客户端操作系统