Search code examples
internet-explorercompatibility-modeie8-compatibility-mode

It seems that "IE=EmulateIE7" will also make "<!--[if lt IE 8]>" be true?


It seems that when the webpage has

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

so that IE 8 will emulate IE 7, then later in the webpage, when there is

<!--[if lt IE 8]> 
  <link href="http://www.example.com/stylesheets/compiled/ie.css" type="text/css" />
<![endif]-->

then it will also be loading ie.css?

That is, it is IE 8, emulating IE 7, and so the lt IE 8 will be true?

Update: but then, the server side variable HTTP_USER_AGENT will be still saying IE 8? Because the browser goes to the server as IE 8, gives IE 8 as the string of HTTP_USER_AGENT, and then the server replies with wanting to emulate IE 7. So if the server language such as PHP detects HTTP_USER_AGENT, it will still be IE 8 in the compatibility mode (IE 7 emulation mode)?


Solution

  • That's the whole point of that meta tag, isn't it? The moment you have this:

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

    IE8 starts behaving on the client-side as IE7:

    • Your pages will all render as they would in IE7
    • Your conditional comments targeting anything older than IE8 (<!--[if lt IE 8]>) will also be read, and the code inside executed, so ie.css is loaded

    However, the IE7 switch only takes place after IE8 reads that meta tag. Since your HTML is returned as part of the response, IE8 has to request it first. Since IE8 has no idea beforehand that this meta tag would appear, the user-agent string it sends is MSIE 8.0. PHP then recognizes it as IE8.