Detect if any kind of IE (MSIE)

JavascriptPhpJqueryInternet Explorer

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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.");
}

Solution 2 - Javascript

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!

Solution 3 - Javascript

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");
}

Solution 4 - Javascript

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)

Solution 5 - Javascript

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.

Solution 6 - Javascript

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 :)
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWorkersGonnaWorkView Question on Stackoverflow
Solution 1 - JavascriptTop QuestionsView Answer on Stackoverflow
Solution 2 - JavascriptSarangaView Answer on Stackoverflow
Solution 3 - Javascriptins0View Answer on Stackoverflow
Solution 4 - JavascriptTimView Answer on Stackoverflow
Solution 5 - Javascriptuser3859423View Answer on Stackoverflow
Solution 6 - JavascriptfabyView Answer on Stackoverflow