方法一:document.documentMode

  1. function getIEVersion () {
  2. // documentMode 属性返回浏览器渲染文档的模式
  3. // 注意:如果没有指定 !DOCTYPE , IE8 以 IE5 模式渲染页面
  4. if (document.documentMode) {
  5. return document.documentMode
  6. }
  7. }
  8. if (getIEVersion() && getIEVersion() < 11) {
  9. window.location.href = ''
  10. }

方法二:navigator

  1. function getIEVersion () {
  2. let e = 99
  3. // appName 属性可返回浏览器的名称
  4. if (navigator.appName === 'Microsoft Internet Explorer') {
  5. // userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值
  6. const t = navigator.userAgent
  7. new RegExp('MSIE ([0-9]{1,}[.0-9]{0,})').exec(t) != null && (e = parseFloat(RegExp.$1))
  8. }
  9. return e
  10. }
  11. getIEVersion() < 11 && (window.location.href = '')