方法一:document.documentMode
function getIEVersion () { // documentMode 属性返回浏览器渲染文档的模式 // 注意:如果没有指定 !DOCTYPE , IE8 以 IE5 模式渲染页面 if (document.documentMode) { return document.documentMode }}if (getIEVersion() && getIEVersion() < 11) { window.location.href = ''}
方法二:navigator
function getIEVersion () { let e = 99 // appName 属性可返回浏览器的名称 if (navigator.appName === 'Microsoft Internet Explorer') { // userAgent 属性是一个只读的字符串,声明了浏览器用于 HTTP 请求的用户代理头的值 const t = navigator.userAgent new RegExp('MSIE ([0-9]{1,}[.0-9]{0,})').exec(t) != null && (e = parseFloat(RegExp.$1)) } return e}getIEVersion() < 11 && (window.location.href = '')