我使用下面的代码来检测浏览器版本,通知用户使用更高版本的IE。但是它在IE11中不能正确工作。
// forbid ie10 below visit
if(navigator.userAgent.match(/msie\s[5-9]/i))
{
... // show a advice page to change ie version
}我发现如果网络发布到服务器,用户会看到ie版本更改的建议。
用户代理字符串: Internet 11 (默认)文档模式5(默认)
当我将文档模式更改为11时,web工作得很好。
我还在html头中使用了下面的代码,但是它不起作用。
<meta http-equiv="X-UA-Compatible" content="IE=11" />发布于 2020-12-25 08:43:57
看起来,如果您使用的是较旧版本的IE浏览器,则需要通知您的站点用户使用IE11浏览器。
样本代码:
<!doctype html>
<html>
<head>
<title>
Test to detect IE browser
</title>
</head>
<body >
<div id="info"></div><br>
<h2>Test Page...</h2>
<script>
function Detect_IE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
return "IE " + parseInt( ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
var rv = ua.indexOf('rv:');
return "IE " + parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
// other browser
return "false";
}
var result=Detect_IE();
if (result=="false")
{
document.getElementById("info").innerHTML +="<h2>Not IE, any other browser....</h2>";
}
else if (result=="IE 11")
{
document.getElementById("info").innerHTML += "<h2>Dear user you are using " + result + ".</h2>";
}
else
{
document.getElementById("info").innerHTML += "<h2>Dear user you are using " + result + " This browser is outdated and not supported by this site. Kindly use supported browser...</h2>";
}
</script>
</body>
</html>
输出:

https://stackoverflow.com/questions/65446424
复制相似问题