views:

518

answers:

4

I have a website depending on vector drawing, for internet explorer i'm using VML and for other browsers i'm using SVG. IE8 however, doesn't have support for neither without falling back to IE7-mode which has VML.

Therefore i'm including <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />.

The problem (well, actually a good thing) is that IE9 now has support for SVG so i don't want it to fall back to IE7-mode which has much worse performance and compatibility. How do i tell only IE8 to fall back to IE7-mode but let IE9 stay in IE9-mode.

Right now i'm doing a server side check on the agent whether to include the EmulateIE7-string in the head or not but i want to avoid this as far as it's possible.

A: 
<!--[if IE 8]>
  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<![endif]-->

It's called conditional comments
http://en.wikipedia.org/wiki/Conditional_comment

Sruly
Does not work. IE8 stays in IE8-mode. I seems like the rendering mode is picked before the conditional comments kick in.
Urjan
Indeed, any use of a conditional comment fixes the documentMode so it cannot be changed by a later `<meta>`.
bobince
Sorry, I didnt test it.
Sruly
A: 

I think what you need is:

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

according to http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx as it states this as "... an example that combines values so that IE8 renders a webpage in IE7 Standards mode while IE9 renders the webpage in IE9’s Standards mode:"

However I for one can't get this to work.

Jon Robson
A: 

The dual mode mentioned by someone else should work (but doesn't) and is the closest thing I've seen in MS documentation that should work as described.

So if you use this:

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

Unfortunately, what you will get is IE8 rendering as IE8 because of the fuzzy version vectoring that the x-ua-compatible engine does. See this document: Defining Document Compatibility: Understanding Content Attribute Values on MSDN. In that section, you'll see that in the first half, they define any version vector defined as larger than the current browser version will be interpreted as the largest available rendering engine. Therefore, emulateIE9 get's translated down to emulateIE8. Stupid.

Then, in the same breath practically, they talk about using multiple version vectors as in the code snippet above to exclude a particular engine. But because of the fuzzy version logic, that would never work. Ah, Microsoft. Fail again.

The reason why using CCs around the meta won't work, is that the browser must have chosen a rendering engine by the time it hits a CC. The x-ua meta must come before anything else in the header except other metas or the title according to MS's own documentation.

If anyone can figure this out, I'm all ears because I'm desperate to exclude IE8 from support while including IE9.

squareman
A: 

Wow Microsoft have really created a nightmare here. We're going to be talking about this well into the future!

Anyway this works for me.

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