判斷瀏覽器類別以及版本
function getExplorerInfo() {
var explorer = window.navigator.userAgent.toLowerCase();
//360
if (window.navigator.userAgent.indexOf('compatible') !== -1) {
console.log('360相容');
}
if(window.navigator.userAgent.indexOf('AppleWebKit') !== -1) {
console.log('360極速模式');
}else{
console.log('360相容模式');
}
//ie
if (explorer.indexOf("msie") >= 0) {
var ver = explorer.match(/msie ([\d.]+)/)[1];
console.log("IE:" + ver)
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判斷是否IE<11瀏覽器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判斷是否IE的Edge瀏覽器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 6) {
console.log(fIEVersion);
} else if(fIEVersion == 7) {
console.log(fIEVersion);
} else if(fIEVersion == 8) {
console.log(fIEVersion);
} else if(fIEVersion == 9) {
console.log(fIEVersion);
} else if(fIEVersion == 10) {
console.log(fIEVersion);
} else {
console.log("IE版本<7");//IE版本<=7
}
} else if(isEdge) {
console.log('edge');//edge
} else if(isIE11) {
console.log(11); //IE11
}else{
console.log("不是ie");//不是ie瀏覽器
}
}
//firefox
else if (explorer.indexOf("firefox") >= 0) {
var ver = explorer.match(/firefox\/([\d.]+)/)[1];
console.log("Firefox:" + ver)
}
//Chrome
else if (explorer.indexOf("chrome") >= 0) {
var ver = explorer.match(/chrome\/([\d.]+)/)[1];
console.log("Chrome:" + ver)
}
//Opera
else if (explorer.indexOf("opera") >= 0) {
var ver = explorer.match(/opera.([\d.]+)/)[1];
console.log("Opera:" + ver)
}
//Safari
else if (explorer.indexOf("Safari") >= 0) {
var ver = explorer.match(/version\/([\d.]+)/)[1];
console.log("Safari:" + ver)
}
}
&nb