Reputation: 424
I use the code below to detect browser version to advice user use higher version IE. But it works in IE11 not correctly.
// forbid ie10 below visit
if(navigator.userAgent.match(/msie\s[5-9]/i))
{
... // show a advice page to change ie version
}
I find if the web publish to server, user will see the ie version change advice.
User agent string : Internet Explorer 11 (Default)
Document mode 5(Default)
When I change Document mode to 11, the web work well.
I also use the code below in html head, but it doesn't work.
<meta http-equiv="X-UA-Compatible" content="IE=11" />
Upvotes: 0
Views: 1466
Reputation: 11335
It looks like you want to inform your site user to use the IE 11 browser if they are using an older version of the IE browser.
Sample code:
<!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>
Output:
Upvotes: 1