52

I dont want to allow users to access my site with Microsoft Internetexplorer (ANY VERSION).

What I´ve found so far was to detect if it´s lower or equal version 10.

A very annoing thing: Internetexplorer >v10 doesn´t admit to be a InternetExplorer.

What i´ve found and tried so far:

if(navigator.appVersion.indexOf("MSIE")!=-1){
alert("You use IE. That´s no good.");
}

or

if ( $.browser.msie ) {
alert( $.browser.version );
}

and

http://msdn.microsoft.com/en-us/library/ie/ms537509%28v=vs.85%29.aspx

I would use any solution if it is in javascript, jquery or php if there is one.

12
  • 2
    Why you wanna do that? Jul 21, 2014 at 8:55
  • 8
    excellent question! +1.. what else can i do to help drive people away from ie?
    – abbood
    Jul 21, 2014 at 8:57
  • 1
    Didnt this if($.browser.msie) work? Jul 21, 2014 at 8:59
  • 6
    I do not believe this is a duplicate +1 :)
    – www139
    Dec 25, 2015 at 0:12
  • 2
    This is not a duplicate. This is a legit question. Perfect for use on an intranet etc.
    – Cagy79
    Jul 31, 2017 at 9:41

6 Answers 6

86

This works for me to detect any Version of the IE 5-11 (Internet Explorer) (Aug/05/2014):

if (navigator.appName == 'Microsoft Internet Explorer' ||  !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
{
  alert("Please dont use IE.");
}
8
  • 5
    Just FYI, as of August 2015, this is not working for me. Interestingly (annoyingly), navigator.appName is set to Netscape instead of Microsoft Internet Explorer.
    – ohio818
    Aug 31, 2015 at 13:42
  • It'd be nice to also check for the version of IE. Sep 2, 2016 at 15:31
  • 2
    navigator.userAgent.match(/rv:11/) you must fix this one because it contains no : marks in your regex string Feb 5, 2017 at 18:37
  • 4
    I confirm that latest versions of IE (not Edge) give "Netscape" as navigator.appName.
    – pHneutre
    Feb 23, 2017 at 15:11
  • 4
    best alert message ever. !! made my life miserable since 3 days Oct 28, 2017 at 9:28
29

This is because each release of Internet Explorer updates the user-agent string.

MSIE tokens have been removed in Internet Explorer 11 and $.browser uses navigator.userAgent to determine the platform and it is removed in jQuery 1.9.

You can use following code to determine the browser with pure java-script.

var isIE = !!navigator.userAgent.match(/Trident/g) || !!navigator.userAgent.match(/MSIE/g);

if(isIE){
 alert("IE"); 
}
else{
 alert("Not IE");   
}

Thanks!

5
  • That´s what he allready wrote in his question....doesn´t work for >10 Jul 21, 2014 at 9:00
  • Yes, sorry, I have updated the answer.
    – Saranga
    Jul 21, 2014 at 10:53
  • 1
    Why does the code use double-negation? (!!)
    – rinogo
    Feb 27, 2017 at 20:38
  • 1
    @rinogo I wondered this myself, having never seen that pattern before. Discovered it's to make the values a boolean as .match() returns an array of results and without them isIE would just be ["Trident"] or ["MSIE"]. One could also write this: var isIE = /Trident/.test(navigator.userAgent) || /MSIE/.test(navigator.userAgent);
    – Omega192
    Mar 24, 2017 at 13:45
  • 11
    const isIE = /Trident|MSIE/.test(navigator.userAgent); is the shorter equivalent
    – fregante
    Apr 4, 2018 at 8:34
7

if you are not interessted wich version of ie the user currently use you can try get it work with detecting if the browser supports the Conditional Compilation Statements

http://msdn.microsoft.com/en-us/library/7kx09ct1%28v=vs.80%29.aspx

if(/*@cc_on!@*/false)
{
    // You use IE. That´s no good.
    alert("oh my god");
}
0
4

You can use conditional compilation , e.g.

<script>
var isIE = false;
/*@cc_on isIE = true; @*/
</script>

But note that IE11 doesn't observe this in Standards Mode. User Agent sniffing is generally a bad idea, but as IE becomes more standards-compliant, it also becomes harder to detect (hopefully also meaning less need to)

0
1

For IE> 10 which is currently IE 11, user-agent carries something in Browser's HTTP request headers

Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko

You can put a check on "rv:11.0" for version 11. Let me know if you need code for this.

1

I've found (maybe in SO) in the past this script and it worked for me (IE 10 too)

<![if IE]>
<script type='text/javascript'>
if(/*@cc_on!@*/false)
var bIsIE = 1;
</script>
<![endif]>

and then

if (typeof (bIsIE) != 'undefined')
{
    //IE :(
}
else
{
    //NOT IE :)
}
1
  • 1
    Doesn't work for me with IE11 with or without compatibility mode
    – Ed Griebel
    Jan 24, 2018 at 16:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.