首页 > 代码库 > 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>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。