https://support.dmeng.net/kill-old-versions-of-ie.html
export function myBrowser() {
let userAgent = navigator.userAgent //取得浏览器的userAgent字符串
console.log('userAgent:', userAgent)
let isOpera = userAgent.indexOf('Opera') > -1 || userAgent.indexOf('OPR') > -1 //判断是否Opera浏览器
let isQQ = userAgent.indexOf('QQBrowser') > -1 //判断是否QQBrowser浏览器
let isUC = userAgent.indexOf('UBrowser') > -1 //判断是否UC浏览器
let isIE =
userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 //判断是否IE7~IE10浏览器
let isIE11 =
userAgent.indexOf('compatible') === -1 && userAgent.indexOf('Trident') > -1 //判断是否IE11浏览器
let isEdge = userAgent.indexOf('Edge') > -1 //判断是否IE的Edge浏览器
let isFF = userAgent.indexOf('Firefox') > -1 //判断是否Firefox浏览器
let isSafari =
userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') === -1 //判断是否Safari浏览器
let isChrome =
userAgent.indexOf('Chrome') > -1 &&
userAgent.indexOf('; Win') > -1 &&
userAgent.indexOf('Safari') > -1 //判断Chrome浏览器
let is360 =
userAgent.indexOf('Chrome') > -1 &&
userAgent.indexOf('; WOW') > -1 &&
userAgent.indexOf('Safari') > -1 //判断360浏览器
if (isIE) {
let reIE = /MSIE (\d+)\.\d+;/
let matchReg = userAgent.match(reIE)
let fIEVersion = matchReg[1]
if (fIEVersion == 7) {
return 'IE7及其以下'
} else if (fIEVersion == 8) {
return 'IE8'
} else if (fIEVersion == 9) {
return 'IE9'
} else if (fIEVersion == 10) {
return 'IE10'
} else {
return '0'
}
return 'IE' //IE版本过低
}
if (userAgent.indexOf('se 2.x') > 0) {
return 'shougou'
}
if (isUC) {
return 'UC'
}
if (isQQ) {
return 'QQBrowser'
}
if (isIE11) {
return 'IE11'
}
if (isOpera) {
return 'Opera'
}
if (isEdge) {
return 'Edge'
}
if (isFF) {
return 'Firefox'
}
if (isSafari) {
return 'Safari'
}
if (isChrome) {
return 'Chrome'
}
if (is360) {
return '360'
}
}
export const isWeiXin = () => {
return ua.match(/microMessenger/i) == 'micromessenger'
}
export const isDeviceMobile = () => {
return /android|webos|iphone|ipod|balckberry/i.test(ua)
}
export const isQQBrowser = () => {
return !!ua.match(/mqqbrowser|qzone|qqbrowser|qbwebviewtype/i)
}
export const isIos = () => {
var u = navigator.userAgent
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
//安卓手机
return false
} else if (u.indexOf('iPhone') > -1) {
//苹果手机
return true
} else if (u.indexOf('iPad') > -1) {
//iPad
return false
} else if (u.indexOf('Windows Phone') > -1) {
//winphone手机
return false
} else {
return false
}
}
export const isPC = () => {
var userAgentInfo = navigator.userAgent
var Agents = [
'Android',
'iPhone',
'SymbianOS',
'Windows Phone',
'iPad',
'iPod'
]
var flag = true
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false
break
}
}
return flag
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="renderer" content="webkit" />
<meta name="force-rendering" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="referrer" content="no-referrer" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title><%= htmlWebpackPlugin.options.title %></title>
<script src="<%= BASE_URL %>iconfont.js"></script>
</head>
<body>
<noscript>
<strong
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work
properly without JavaScript enabled. Please enable it to
continue.</strong
>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<!-- IE 浏览器跳转提示升级页面 start -->
<script>
if (
/*@cc_on!@*/ false ||
(!!window.MSInputMethodContext && !!document.documentMode)
) {
window.open(
'https://support.dmeng.net/upgrade-your-browser.html?referrer=' +
encodeURIComponent(window.location.href)
)
}
</script>
<!-- IE 浏览器跳转提示升级页面 end -->
<script>
function isIE() {
if (!!window.ActiveXObject || 'ActiveXObject' in window) {
return true
} else {
return false
}
}
</script>
</body>
</html>