In asp.net-mvc, is there a way to distinguish between IE7 users and IE8 users who are in compatibility mode?

For IE7 users, I want to add a specific banner, "Please upgrade now." I thought I had it, but I found out that my banner appears on those who had IE8, but compatibility mode was turned on by default.

Is there a difference between the two situations, so I can change my message:

Upgrade from IE7 to . You are using IE8 but using compatibility mode, please disable it

Here is the code I'm using now in my view:

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

but if I test in IE8 with a compatibility view using the code above or this client-side code:

 <!--[if lte IE 7]> 

it returns true and is displayed as IE7. How can I distinguish two?

+6
source share
4 answers

According to user-agents.org and some of the discussions related to the other answers, you can distinguish between three cases by checking the user agent string you received.

  • For MSIE 7.0: Check for MSIE 7.0 and the absence 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 compatibility mode: Check for MSIE 7.0 and 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 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 complete these checks, consult the next tutorial , replacing all this bullshit on the iPhone and mobile devices with the browsers you are checking for. :)

Best of luck with your application.

+7
source

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

+1
source

Microsoft The concept of User-Agent strings provides a fairly detailed explanation of user agent strings sent by different versions of IE (including compatibility mode). If you determine that the user agent displays MSIE 7.0 , look for Trident in the user agent string, which indicates that the browser is actually IE8 + in compatibility mode.

There is a section in the document explaining the Trident token and how it works.

+1
source

I think TGH is right.

Another option is to use the built-in jQuery functions for a complete check: browser type, browser version and browser mode:

 $.browser.msie $.browser.version document.documentMode 
0
source

Source: https://habr.com/ru/post/911645/


All Articles