网上百度了下,自己又整理了下,最后得到方法
function getSys() {
var sys;
var sUserAgent = navigator.userAgent.toLowerCase();
/* 系统判断 */
if(sUserAgent.match(/Windows NT 5.0/i)=="windows nt 5.0"){
sys='win2000'; //win2000
}
else if(sUserAgent.match(/Windows NT 5.1/i)=="windows nt 5.1"){
sys='winxp'; //winxp
}
else if(sUserAgent.match(/Windows NT 5.2/i)=="windows nt 5.2"){
sys='win2003'; //Win2003操作系统
}
else if(sUserAgent.match(/Windows NT 6.0/i)=="windows nt 6.0"){
sys='winVista'; //WinVista操作系统
}
else if(sUserAgent.match(/Windows NT 6.1/i)=="windows nt 6.1"){
sys='win7'; //win7
}
else if(sUserAgent.match(/android/i)=="android"){
sys='android'; //android
}
else if(sUserAgent.match(/iphone/i)=="iphone"){
sys='iphone'; //iphone
}
else{
sys='当前操作系统未录入,请发送当前截图联系管理员 \n'+sUserAgent;
}
/*
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
*/
/*
var tt='';
for(var i=str.length;i>0;i--){
tt+=i+' = '+str[i]+'\n';
}
alert(tt);
*/
return sys;
}
function getBrowser() {
var browse;
var str=navigator.userAgent.split(' ');
var str_sel='';
var n=0;
switch(getSys()){
case 'iphone':
n=str.length-4;
break;
case 'android':
n=str.length-5;
break;
default:
n=str.length-2;
break;
}
str_sel=str[n];
console.log('str_sel==='+str_sel);
/* 浏览器判断 */
if(str_sel.match(/ ie/i)=="ie"){
browse='IE'; //IE
}
else if(str_sel.match(/firefox/i)=="firefox"){
browse='firefox';
}
else if(str_sel.match(/Chrome/i)=="Chrome"){
browse='chrome';
}
else if(str_sel.match(/UBrowser/i)=="UBrowser"){
browse='uc';
}
else if(str_sel.match(/opera/i)=="opera"){
browse='opera';
}
else if(str_sel.match(/safari/i)=="safari"){
browse='safari';
}
else if(str_sel.match(/micromessenger/i)=="micromessenger"){
browse='micromessenger'; //微信浏览器
}
else{
browse='当前浏览器类型未录入,请发送当前截图给联系管理员 \n'+navigator.userAgent;
}
console.log('浏览器='+browse);
/*
var tt='';
for(var i=str.length;i>0;i--){
tt+=i+' = '+str[i]+'\n';
}
console.log(tt);
*/
return browse;
}