日期:2014-05-16  浏览次数:20440 次

JS获取客户端操作系统类型
我现做个站点,需要获取用户的操作系统类型。用js实现,网上找了好多都不全面。我要区分window98 window2000 window2003
WindowsXP WindowsVista Windows7 Linux Mac iPhone iPad android…… 这些都要区分开,谁帮我弄个全面点的啊,谢啦

------解决方案--------------------
<html>
<head>
<script type="text/javascript">
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()); 
</script>
</head>
<body>
</body>
</html>

iPhone iPad android 这种没测试过。你可以试试Js打印出来看看具体的navigator.platform,然后自己扩展上面的js函数