Detect if any kind of IE (MSIE)

<>

This question already has an answer here:

Answers


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

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!


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

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)


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.


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

Need Your Help

UITapGestureRecognizer in UIScrollView subview

objective-c uiscrollview uiimageview uigesturerecognizer

I'm trying to use a single tap recognizer in an imageView (that is also a scrollView child).

EF 4.1 - Model Relationships

asp.net-mvc-3 entity-framework-4 entity-relationship ef-code-first entity-framework-4.1

I'm trying to create a quick ASP.NET MVC 3 application using the RC version of EF 4.1. I have two models: