views:

1321

answers:

5

Is there anyway to determine if an IE8 browser has compatibility view switched on?

I can't seem to find anything on Google, and so I'm wondering if this is a piece of information that is available...

Why you ask!? I'm trying to track down a bug in our application. I'm piecing through the Elmah logs and there seems to be a trend; this error is generally thrown by IE8. I tried to repo the defect in my copy of IE8, but couldn't. I want to narrow down the culprits, and thought this might be a way to do it.

A: 

Well, I don't know how to detect if it's turned on... but you can try and force the client's browser into a particular mode:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

In theory, by doing this you would know if it's turned on or not.

Edit: I know this is a bad answer, but at least it's something :)

hamlin11
A: 

I belive it is contained in the User Agent string:

"A new tag in the User Agent string allows for detection of clients viewing your site in Compatibility View. This tag is also present in the “normal” Internet Explorer 8 User Agent string."

"In the event that a user selects Compatibility View for your site, you can “bring them back” to your desired layout mode via use of the version targeting tag / HTTP header. A new content value, ‘IE=EmulateIE8’, rounds out the list of supported values and assists in this particular scenario."

More information here: http://blogs.msdn.com/ie/archive/2008/08/27/introducing-compatibility-view.aspx

ericvg
See this answer http://stackoverflow.com/questions/1208837/how-can-i-detect-if-ie8-is-running-in-compatibility-view/1208951#1208951: IE7 produces the same User Agent as IE8 in compatibility mode, so user agent doesn't work
Gavin Miller
+1  A: 

In Javascript, use document.documentMode

See http://msdn.microsoft.com/en-us/library/cc196988%28VS.85%29.aspx for details.

Alohci
This won't help if page is in Quirks mode
horseman
A: 

Evidently IE8 has some new properties

document.documentMode

and

document.compatMode

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

Tommy
compatMode is a legacy property, and isn't very useful here. It tells you whether the page is in quirks mode.
EricLaw -MSFT-
A: 

Check for the "Trident/4.0" in the userAgent. It should be present for IE-8 only. http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/33e0ed49-11fb-4d91-857c-a35496e90075

horseman