首页 > 代码库 > javascript 判断系统设备

javascript 判断系统设备

 1 <script> 2  3 function detectOS() {  4 var sUserAgent = navigator.userAgent;  5  6 var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");  7 var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");  8 if (isMac) return "Mac";  9 var isUnix = (navigator.platform == "X11") && !isWin && !isMac; 10 if (isUnix) return "Unix"; 11 var isLinux = (String(navigator.platform).indexOf("Linux") > -1); 12 13 var bIsAndroid = sUserAgent.toLowerCase().match(/android/i) == "android";14 if (isLinux) {15 if(bIsAndroid) return "Android";16 else return "Linux"; 17 }18 if (isWin) { 19 var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1; 20 if (isWin2K) return "Win2000"; 21 var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || 22 sUserAgent.indexOf("Windows XP") > -1; 23 if (isWinXP) return "WinXP"; 24 var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1; 25 if (isWin2003) return "Win2003"; 26 var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1; 27 if (isWinVista) return "Vista"; 28 var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1; 29 if (isWin7) return "Windows 7"; 30 31  var isWin8 = sUserAgent.indexOf("Windows NT 6.2") > -1 || sUserAgent.indexOf("Windows 8") > -1;32 if (isWin8)return "Windows8";33 } 34 return "other"; 35 } 36 37 document.writeln("您的操作系统是:" + detectOS()); 38 alert(detectOS());39 40 </script>