Javascript识别浏览器+操作系统
Javascript识别浏览器+操作系统
var os_mapping = { 'win98': 1, 'winxp': 2, 'win2000': 3, 'win2003': 4, 'win7': 5, 'win8': 6, 'vista': 7, 'mac': 8, 'lin': 9, 'other': 20 }, browser_mapping = { 'ie10': 1, 'ie9': 2, 'ie8': 3, 'ie7': 4, 'ie6': 5, 'chrome': 6, 'sogou': 7, 'ff': 8, '360': 9, 'safari': 10, 'opera': 11, 'maxthon': 12, 'qq': 13, 'liebao': 14, 'other': 20 } function detectBrower() { //使用jquery是1.8.2可是使用$.browser var b = $.browser, ua = navigator.userAgent if (ua.indexOf("Maxthon") != -1){ return browser_mapping['maxthon'] }else if (ua.indexOf("360SE") != -1){ return browser_mapping['360'] }else if(ua.indexOf("SE 2.X MetaSr 1.0") != -1){ return browser_mapping['sogou'] }else if(ua.indexOf("QQ") != -1){ return browser_mapping['qq'] }else if(ua.indexOf("LBBROWSER") != -1){ return browser_mapping['liebao'] }else if (b.chrome) { return browser_mapping['chrome'] } else if (b.msie) { var v = parseInt(b.version) switch (v) { case 6: return browser_mapping['ie6'] case 7: return browser_mapping['ie7'] case 8: return browser_mapping['ie8'] case 9: return browser_mapping['ie9'] case 10: return browser_mapping['ie10'] default: return browser_mapping['other'] } } else if (b.safari) { return browser_mapping['safari'] } else if (b.mozilla) { return browser_mapping['ff'] } else if (b.opera) { return browser_mapping['opera'] } else { return browser_mapping['other'] } } 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 os_mapping["mac"] } else if ((navigator.platform == "X11") && !isWin && !isMac) { return os_mapping["other"]; } else if (String(navigator.platform).indexOf("Linux") > -1) { return os_mapping["lin"] } else if (isWin) { if (sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1) { return os_mapping["win2000"] } if (sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1) { return os_mapping["winxp"] } if (sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1) { return os_mapping["win2003"] } if (sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1) { return os_mapping["vista"] } if (sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1) { return os_mapping["win7"] } if (sUserAgent.indexOf("Windows NT 6.2") > -1 || sUserAgent.indexOf("Windows 8") > -1) { return os_mapping["win8"] } } else { return os_mapping["other"]; } }
----- 但愿人长久,千里共婵娟
(如果你对本篇博文有任何问题和赞同,请回复告诉我)