Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE10 and below Browser detection

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");
            }
like image 458
priya Avatar asked Jan 13 '16 04:01

priya


People also ask

What version of Internet Explorer can be detected in JavaScript?

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.

How do I check if a website works in Internet Explorer?

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.

What happened to pointer events in IE10 and IE11?

// 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.

How do I use the F12 tool in Internet Explorer?

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.


2 Answers

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.

like image 97
libertyernie Avatar answered Dec 10 '22 14:12

libertyernie


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.

like image 39
Simba Avatar answered Dec 10 '22 13:12

Simba