What is the point of X-UA-Compatible?

2019-03-27 00:18发布

I don't understand at all what <meta http-equiv="X-UA-Compatible" content="..." /> is for...

Can someone explain...

  • What it does for different values of content?
  • What omitting it does for different browsers?
  • What the motivation for it is?
  • Why it exists?

2条回答
对你真心纯属浪费
2楼-- · 2019-03-27 00:25

It's a horrible hack to cater for different bugs or incomplete implementations in various versions of the Internet Explorer browser. For example, this:

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

will instruct IE9 to pretend it's really IE7 to avoid any problems that might occur if your site works in IE7 but not IE9.

查看更多
狗以群分
3楼-- · 2019-03-27 00:35

This meta tag (or http header) only has meaning for IE8 and up. It is a way to force IE to render the page as an older version would have. Omitting it has no effect, it only as effect if used.

Possible values are "IE=" followed by any of the following:

  • Edge - Render as whatever the latest version of IE is
  • IE9 - Render as IE9 in standards mode
  • Emulate IE9 - Render as IE9 but use the <!DOCTYPE> to determine the mode
  • IE8 - Render as IE8 in standards mode
  • Emulate IE8 - Render as IE8 but use the <!DOCTYPE> to determine the mode
  • IE7 - Render as IE7 in standards mode
  • Emulate IE7 - Render as IE7 but use the <!DOCTYPE> to determine the mode
  • IE5 - Render as IE7 in quirks mode

Additionally, you can add a comma followed by Chrome=1 to tell IE to render the page using Google Chrome Frame if it is installed. So you might have a tag that looks like this:

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">

Or, instead of that, you can also specify to use GCF for for a specific version of IE and below like this:

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=IE8">

Which means to use GCF if it is installed and IE is at version 8 or below otherwise, render as the latest installed version of IE.

So, it's obvious that it is useful to be able to make older versions of IE use GCF but that was probably not Microsoft's intention when they implemented this. It can be used for compatibility with old sites that only work in older versions of IE and can't be easily fixed but that's kind of silly. Personally, I find it useful for testing. Since it's generally not so simple to test multiple versions of IE from a single development machine, this provides a decent solution.

查看更多
登录 后发表回答