Detect IE8 Compatibility Mode [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-27 01:33:41

IE8 includes a trident token in the User-Agent string regardless of compatibility mode.

See MSDN for more details: http://blogs.msdn.com/ie/archive/2009/01/09/the-internet-explorer-8-user-agent-string-updated-edition.aspx

IE7 on Windows Vista
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)

IE8 on Windows Vista (Compatibility View)
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0)

IE8 on Windows Vista
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)

You need to check the value of document.documentMode which will have a value of 8 in true IE8 mode and 7 in IE7 mode. The user agent string will be identical in both cases and will still state IE8. Note that this JavaScript variable is only available in IE8.

Mark Kamoski

FYI, for details on how to detect Compatibility Mode (AKA how to detect Compatibility View), please consider viewing the following link...

http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx

...which shows some helpful information.

Problem is actually even more complex when you deal with links coming to your site from IE8 emulation BLACKLIST sites such as Facebook.

A shared link on Facebook causes your links to open in a Popup - IF THE "INCLUDE UPDATE WEBLISTS" is checked on the compatibility view settings, which is checked by default, the popup window sees the Blacklist referrer from Facebook and opens the window in Blacklist mode initially. When detecting in background for Trident\4.0 - you will see the value, and set the downlevel CSS.

However, after the browser loads it switches out of Compat mode and changes to STANDARD mode without refreshing. You therefore have the wrong CSS for standard modes assigned.

Solution - Force the IE Browser out of Compatibility mode. Yep - seems odd, why let a user go downlevel on your site if you don't need to.

Just like Downlevel you set IE=EmulateI7 to force the browser down you can add IE=EmulateIE8 and force the user to view your page in IE8 Standard. this mode even removes their ability to select Compatibility View and reduce your Test Needs for that mode

Not quite "detecting IE8 compatibility mode" but it might help just as well:

If you have access to the server itself, you can send out an HTTP Header, take a look at Mike Ormond's blog about it. The MSDN page for Implementing the Meta Switch on IIS has details of the header and how to set/send it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!