I just want to target only IE10 and below versions IE browsers. Please help me for this. I have tried below code
var userAgent = navigator.userAgent;
var regexIe8 = new RegExp("Trident(\/4.0)|(Trident\/5.0)");
if (regexIe8.test(userAgent)) {
alert("test1");
}
else {
alert("test2");
}
Internet Explorer browser of versions 10 and older can be detected in JavaScript by checking existence of the nonstandard document.all object available only in IE10 and older. Exact version of IE can be detected by additional checking of existence of standard global objects added in specific IE versions.
To see if the site works in the Internet Explorer 5, Internet Explorer 7, Internet Explorer 8, Internet Explorer 9, Internet Explorer 10, or Internet Explorer 11 document modes: Open the site in Internet Explorer 11, load the F12 tools by pressing the F12 key or by selecting F12 Developer Tools from the Tools menu, and select the Emulation tab.
// Pointer events were added in IE10 (window.PointerEvent). // The syntax changed in IE 11 (vendor prefix was removed). // If pointer events are supported - and - the new syntax is supported, we know it is IE 11.
Open the site in Internet Explorer 11, load the F12 tools by pressing the F12 key or by selecting F12 Developer Tools from the Tools menu, and select the Emulation tab. Run the site in each document mode until you find the mode in which the site works.
In Internet Explorer 11, Microsoft took out the "MSIE", so it now looks like this:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
So you could just check for the presence of "MSIE" to tell you if it's an old version.
if (navigator.userAgent.indexOf("MSIE") >= 0) {
document.write("You are using an unsupported version of Internet Explorer. Please upgrade to Internet Explorer 11 or use a different web browser.");
}
Just note that if Internet Explorer is in compatibility view, and you haven't specified an X-UA-Compatible header, it will identify itself as IE 7 and act like it too.
Using conditional comments instead of Javascript detection:
<!--[if IE]>
<div class='old-browser'>You are running an un-supported version of Internet Explorer. Please upgrade</div>
<![endif]-->
Just stick that directly in your page where you want the notification to appear. No Javascript required (although you can, of course, use JS here if you want to).
Note that IE10 no longer supports conditional comments, so you just need to check [if IE]
to catch all versions of IE up to IE9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With