码迷,mamicode.com
首页 > Web开发 > 详细

js如何判断不同的操作系统

时间:2017-08-26 18:41:08      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:logs   pre   tle   write   如何   操作系统   func   windows 7   tor   

<html>
<head>
<title>判断操作系统</title>
<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); 

var bIsAndroid = sUserAgent.toLowerCase().match(/android/i) == "android";
if (isLinux) {
if(bIsAndroid) return "Android";
else 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()); 
alert(detectOS());
</script>
</head>
<body>
</body>
</html>

  

js如何判断不同的操作系统

标签:logs   pre   tle   write   如何   操作系统   func   windows 7   tor   

原文地址:http://www.cnblogs.com/mmykdbc/p/7435736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!