dbsd_kczx/src/utils/browser.js

38 lines
1008 B
JavaScript
Raw Normal View History

2022-03-10 09:47:29 +08:00
//判断是否IE<11浏览器
export function isIE() {
2022-06-10 10:44:44 +08:00
return navigator.userAgent.indexOf('compatible') > -1 && navigator.userAgent.indexOf('MSIE') > -1;
2022-03-10 09:47:29 +08:00
}
export function isIE11() {
2022-06-10 10:44:44 +08:00
return navigator.userAgent.indexOf('Trident') > -1 && navigator.userAgent.indexOf('rv:11.0') > -1;
2022-03-10 09:47:29 +08:00
}
//判断是否IE的Edge浏览器
export function isEdge() {
2022-06-10 10:44:44 +08:00
return navigator.userAgent.indexOf('Edge') > -1 && !isIE();
2022-03-10 09:47:29 +08:00
}
export function getIEVersion() {
2022-06-10 10:44:44 +08:00
let userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
let isIE = isIE();
let isIE11 = isIE11();
let isEdge = isEdge();
2022-03-10 09:47:29 +08:00
if (isIE) {
2022-06-10 10:44:44 +08:00
let reIE = new RegExp('MSIE (\\d+\\.\\d+);');
reIE.test(userAgent);
let fIEVersion = parseFloat(RegExp['$1']);
2022-03-10 09:47:29 +08:00
if (fIEVersion === 7 || fIEVersion === 8 || fIEVersion === 9 || fIEVersion === 10) {
2022-06-10 10:44:44 +08:00
return fIEVersion;
2022-03-10 09:47:29 +08:00
} else {
2022-06-10 10:44:44 +08:00
return 6; //IE版本<7
2022-03-10 09:47:29 +08:00
}
} else if (isEdge) {
2022-06-10 10:44:44 +08:00
return 'edge';
2022-03-10 09:47:29 +08:00
} else if (isIE11) {
2022-06-10 10:44:44 +08:00
return 11;
2022-03-10 09:47:29 +08:00
} else {
2022-06-10 10:44:44 +08:00
return -1;
2022-03-10 09:47:29 +08:00
}
2022-06-10 10:44:44 +08:00
}