判断是否是ie浏览器,如果是则返回版本
getIEVersion() {
const userAgent = navigator.userAgent
const isIE = isIE()
const isIE11 = isIE11()
const isEdge = isEdge()
//判断是否是ie浏览器,方法见下方
if (isIE) {
const reIE = new RegExp('MSIE (\\d+\\.\\d+);')
reIE.test(userAgent)
const fIEVersion = parseFloat(RegExp['$1'])
if (fIEVersion === 7 || fIEVersion === 8 || fIEVersion === 9 || fIEVersion === 10) {
return fIEVersion
} else {
return 6
}
} else if (isIE11) {
return 11
} else if (isEdge) {
return 'edge'
} else {
return -1
}
}
isIE() {
return navigator.userAgent.indexOf('compatible') > -1 &&
navigator.userAgent.indexOf('MSIE') > -1
}
isIE11() {
return navigator.userAgent.indexOf('Trident') > -1 &&
navigator.userAgent.indexOf('rv:11.0') > -1
}
isEdge() {
return navigator.userAgent.indexOf('Edge') > -1 && !isIE()
}