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.

WorkersGonnaWork
  • 561
  • 1
  • 4
  • 5
  • 2
    Why you wanna do that? – brainless coder Jul 21 '14 at 08:55
  • Because he doesn´t want to support IE users maybe? – Top Questions Jul 21 '14 at 08:55
  • 8
    excellent question! +1.. what else can i do to help drive people away from ie? – abbood Jul 21 '14 at 08:57
  • here you can find a proper example http://stackoverflow.com/a/10965091/2481383 – VladH Jul 21 '14 at 08:58
  • For IE 11 check for `Trident/7.0; rv:11.0` in user_agent – Mark Miller Jul 21 '14 at 08:59
  • 1
    Didnt this `if($.browser.msie)` work? – Pratik Joshi Jul 21 '14 at 08:59
  • 1
    Might be helpful: http://stackoverflow.com/questions/17447373/how-can-i-target-only-internet-explorer-11-with-javascript – Mark Miller Jul 21 '14 at 09:02
  • There is a difference between not wanting to support and actively blocking. It's an interesting question from an educational point of view, but why would you want to do this in production code, except when you're a Mozilla employee and want to prove that IE is bad. – GolezTrol Jul 21 '14 at 09:04
  • @GolezTrol Supporting IE in any kind isn´t fun...maybe just an "tip" in the corner that you shouldn´t use IE for a better user expirience – Top Questions Jul 21 '14 at 09:09
  • For IE6 or even 8 or 9, it's a different story, because they are outdated, but IE11 is a modern browser like the others. Taking small differences between browsers into account should be a part of your job as a web developer. Unnecessarily confusing and scaring your users isn't really part of a 'better user experience'. – GolezTrol Jul 21 '14 at 09:20
  • 6
    I *do not believe this is a duplicate* +1 :) – www139 Dec 25 '15 at 00:12
  • 2
    This is not a duplicate. This is a legit question. Perfect for use on an intranet etc. – Cagy79 Jul 31 '17 at 09:41

6 Answers6

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.");
}
Top Questions
  • 1,862
  • 4
  • 26
  • 38
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!

Saranga
  • 3,178
  • 1
  • 18
  • 26
  • That´s what he allready wrote in his question....doesn´t work for >10 – Top Questions Jul 21 '14 at 09:00
  • Yes, sorry, I have updated the answer. – Saranga Jul 21 '14 at 10:53
  • 1
    Why does the code use double-negation? (`!!`) – rinogo Feb 27 '17 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 '17 at 13:45
  • 11
    `const isIE = /Trident|MSIE/.test(navigator.userAgent);` is the shorter equivalent – fregante Apr 04 '18 at 08: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");
}
ins0
  • 3,918
  • 1
  • 20
  • 28
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)

Tim
  • 8,036
  • 2
  • 36
  • 52
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 :)
}
faby
  • 7,394
  • 3
  • 27
  • 44