Walter Rumsby's Web Site
IE 8 and the User Agent String
12 Aug 2009 at 12:00Earlier this week I had the opportunity to get a better understanding of IE 8's Browser Mode and Document Mode when trying to diagnose an issue that only a coworker could reproduce. I'd marked an issue as resolved, while he was still experiencing the problem.
There was a bit of back and forward where we compared version numbers, made sure caches were cleared, inspected response headers, etc. until we realised the key difference was that he was running the default Intranet Zone settings, where "Display intranet sites in Compatibility View" is enabled, while I was not.
I then noticed that when running with Browser Mode: Internet Explorer 8 Compatibility View the User-Agent request header identifies itself as MSIE 7.0. When running with Browser Mode: Internet Explorer 8 the User-Agent identifies itself as MSIE 8.0. This is case even if the Document Mode is Internet Explorer 8 Standards (e.g. even if you have set the X-UA-Compatible response header or meta element to IE=8).
From IE8 and the X-UA-Compatible situation:
It is entirely possible to encounter IE8 sending the IE7 User Agent string to the server while using the IE8 Standards Mode rendering engine; conversely, you can encounter the IE8 User Agent string while rendering in IE7's engine.
This has one major consequence: you cannot rely on the user agent string when dealing with IE 8. The Browser Mode is entirely different to the rendering mode (aka the Document Mode).
Luckily IE 8 provides a new property, document.documentMode, which you can use to work out which rendering mode is being used. If you need to do something specific for IE 8 Standards Mode you can work out if that rendering mode is being used by checking if (document.documentMode == 8).
As part of this work I developed a greater understanding of what the various Browser Modes mean:
- Internet Explorer 7 - act as IE 7 (meaning you can't use Internet Explorer 8 Standards Document Mode even if
X-UA-Compatible: IE=8; report User Agent versionMSIE 7.0) - Internet Explorer 8 - act as IE 8 (if
X-UA-Compatibleis set follow this flowchart to choose the Document Mode; otherwise rely on the DOCTYPE to chose between Quirks Mode and IE 8 Standards Mode; report User Agent versionMSIE 8.0) default for the Internet Zone - Internet Explorer 8 Compatibility View - act as IE 8 in Compatibility View (choose the Document Mode as for Browser Mode: IE8, choose between Quirks Mode and IE 7 Stanards Mode if there is no
X-UA-Compatibleheader/meta; report User Agent versionMSIE 7.0) default for the Intranet Zone
Initially it's quite confusing, but if you sit with it for a while it makes sense - for a user visiting your site the things that will influence the Browser Mode and Document Mode are:
- Compatibility View Settings
- Intranet Zone vs. Internet Zone
- DOCTYPE
X-UA-Compatible- Have they changed the Browser Mode or Document Mode using the Developer Toolbar
o_O