6

For IE7 users, I want to put in some specific "Please upgrade now" banner. I thought i had this but i found out my banner was popping up on people who had IE8 but had compatibility mode turned on by default.

Is there anyway to differentiate between these two situations so I can change my message from:

Please update from IE7 to You are using IE8 but you are using compatibility mode, please switch this off

Here is the code that i am using now in my View:

You are using <b><% = Request.Browser.Browser + ", Version: " + Request.Browser.Version%>

but if I test in IE8 with compatability view, by using the above code or this code on the client side:

<!--[if lte IE 7]>

it returns true and shows up as IE7. How can i differentiate the two ?

leora
  • 188,729
  • 360
  • 878
  • 1,366
  • I checked with the IE folks and they have confirmed MrGomez is correct - the Trident token of the UA string is the way to do this. See my addtional comments under MrGomez answer. Consider retagging, this has nothing to do with MVC – RickAndMSFT Apr 04 '12 at 23:04

4 Answers4

7

According to user-agents.org and some of the discussion linked by other answers, you can differentiate between the three cases by checking the user agent string you've received.

  • For MSIE 7.0: Check for MSIE 7.0 and the lack of Trident

    For example: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 2.0.50727)

  • For MSIE 8.0 in compatability mode: Check for MSIE 7.0 and the presence of Trident/4.0

    For example: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1;Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0)

  • For MSIE 8.0 in standard mode: Check for MSIE 8.0

    For example: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)

To perform these checks, consult the following tutorial, replacing all of this nonsense about iPhones and mobile devices with the browsers you're checking for. :)

Best of luck with your application.

Community
  • 1
  • 1
MrGomez
  • 23,788
  • 45
  • 72
  • 1
    If you are looking for `Trident/4.0`, you'll falsely flag users in IE7 compatibility under IE9, which is represented by `Trident/5.0`. – saluce Apr 04 '12 at 14:03
  • @saluce The question asks about partitioning IE8 and IE7 specifically. But, that's a useful improvement for an additional case that was not considered. Thank you! – MrGomez Apr 04 '12 at 17:09
  • 1
    I checked with the IE folks and they have confirmed Trident token of the UA string is the way to do this. Of course the site can also specify a document mode with X-UA-Compatible so the Compatibilty View button won’t even appear and if the user’s already pressed the Compatibility View button for that domain, the document mode specific by the site will trump the CV button. That way you know the IE8 user will always get IE8 Mode. – RickAndMSFT Apr 04 '12 at 23:03
  • @Rick.Anderson-at-Microsoft.com That's extremely helpful first party information. Thank you! – MrGomez Apr 04 '12 at 23:18
1

Microsoft's Understanding User-Agent Strings document gives a pretty thorough explanation of the user agent strings sent by different IE versions (including compatibility mode). If you determine that a user-agent is displaying MSIE 7.0, look for Trident in the user agent string, which indicates that the browser is actually IE8+ in compatibility mode.

The document has a section explaining the Trident token and how it works.

saluce
  • 13,035
  • 3
  • 50
  • 67
1

Putting this "<meta http-equiv="X-UA-Compatible" content="IE=8">" in your header will make IE8 not load up in compatability mode

TGH
  • 38,769
  • 12
  • 102
  • 135
  • I think you missed something in your answer :) – joshuahealy Mar 26 '12 at 05:02
  • But I think it might load up in IE 8 document mode for IE 9 though, so it might just push the problem one version up :-) – TGH Mar 26 '12 at 05:04
  • `content="IE=edge"` will make IE8 act like IE8 and IE9 act like IE9. – SpliFF Mar 26 '12 at 05:34
  • @TGH - thanks, this is helpful but still doesn't give me a way to check . . are you saying this line will override whatever the person's browser settings are ? – leora Mar 26 '12 at 13:18
  • 1
    Yes, I confirmed with the IE team that the site can also specify a document mode with X-UA-Compatible so the Compatibilty View button won’t even appear and if the user’s already pressed the Compatibility View button for that domain, the document mode specific by the site will trump the CV button. That way you know the IE8 user will always get IE8 Mode. – RickAndMSFT Apr 04 '12 at 23:08
0

I believe TGH is right.

Another option is to use jQuery's built-in functions to fully test the: browser type, browser version, and browser mode:

$.browser.msie
$.browser.version
document.documentMode
john_science
  • 6,325
  • 6
  • 43
  • 60