获取ie版本

function IEVersion() {
  let userAgent = navigator.userAgent //取得浏览器的userAgent字符串
  let isIE =
    userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 //判断是否IE<11浏览器

  if (isIE) {
    let reIE = new RegExp('MSIE (\\d+\\.\\d+);')
    reIE.test(userAgent)
    let fIEVersion = parseFloat(RegExp['$1'])
    switch (fIEVersion) {
      case 7:
        return 7
      case 8:
        return 8
      case 9:
        return 9
      case 10:
        return 10
      default:
        return 6 //IE版本<=7
    }
  }

  let isEdge = userAgent.indexOf('Edge') > -1 && !isIE
  if (isEdge) {
    return 'edge' //edge
  }

  let isIE11 =
    userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1
  if (isIE11) {
    return 11
  }

  return -1 //不是ie浏览器
}

你可能感兴趣的:(兼容问题,js)