Вопрос

I don't realy understand how these modes works, for example if i add

<!DOCTYPE> to make it html5 document and then add

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

IE would render in IE 9 standarts right?

But my question is what if user doesn't have IE 9 but have IE 6 or 7 and my page would have some features that only works with IE 9 would it still somehow work or not?

Это было полезно?

Решение

Firstly, the way you wrote <!DOCTYPE> on its own in the question isn't valid; you need to specify which doctype to use. If you want to use HTML5, then the doctype line should look like this:

<!DOCTYPE html>

When you have a working doctype, IE will render the page in Standard Mode. Without a doctype, IE will use Quirks mode. Quirks mode is basically an IE5-compatibility mode, with lots of non-standard stuff that breaks in every other browser. You should therefore always use a doctype.

Secondly X-UA-Compatible: This tells IE to use a particular rendering mode, if it can.

Obviously, older versions of IE can't use the rendering mode of newer IE versions, so this tag is also really only of any use for backward compatibility reasons. So the direct answer to your question is 'No': IE6 will never be able to render in IE9 mode, and nor will IE7 or IE8.

IE8 is able to use IE7-compatibility mode and IE9 has both IE8 and IE7 compatibility modes. This tag will trigger IE to use those modes rather than its standard mode.

This is useful as a quick-fix solution if your site was written for an old version of IE and doesn't work properly in newer versions. This is fine if you're in an internal network where everyone is forced to use IE, but on the wider internet you also need to support other browsers, and if a site works in IE8 but breaks in IE9, then there's a good chance it'll break in other browsers too. I would therefore suggest that X-UA-Compatible isn't really all that useful in the real world.

However, there is one case where it is useful to include it: There are config settings in IE that can be set to automatically trigger backward compatibility mode. So an IE8 user might be in IE7 mode without even knowing it.

This is obviously a problem, but specifying X-UA-Compatible to a higher value will force IE to take the newer rendering mode instead. This is a good thing.

In this case, however, you shouldn't be specifying the IE version to use -- because if you specify IE=9, what happens to IE10 users? Instead, you should use the special-case value edge. This forces IE to use the latest rendering mode that it has available to it, regardless of any other settings. In most cases, this is what you want to do. The code would look like this:

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

Hope that helps.

Oh, and by the way, X-UA-Compatible can also be specified in the HTTP headers instead of inside the HTML code.

Другие советы

No, it would not somehow work - that's completely impossible. How would IE 6 get an IE 9 rendering engine without updates?

Indeed, IE 7 and earlier don't even support X-UA-Compatible:

As of Windows Internet Explorer 8, the httpEquiv attribute also supports a value of x-ua-compatible, which allows developers to specify the document compatibility mode that Windows Internet Explorer should use to display a webpage. To do this, set the content attribute to a String value containing a comma-delimited list of one or more of the following values.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top