Bad value X-UA-Compatible for attribute http-equiv

2019-01-10 08:28发布

I have used the same meta that HTML5 Boilerplate is using, and the W3C HTML validator complains:

Bad value X-UA-Compatible for attribute http-equiv on element meta.

<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>

What is wrong with this meta tag?

8条回答
Deceive 欺骗
2楼-- · 2019-01-10 08:50

If you're looking to make it technically valid (everyone loves to see the green favicon) w/o effecting any functionality, you should be able to just wrap it in a "if IE" tag.

<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
查看更多
ら.Afraid
3楼-- · 2019-01-10 08:54

.. may this be a good answer?

Set HTTP Header with PHP:

This is not my own work but I hope it is useful to others too.

查看更多
爷、活的狠高调
4楼-- · 2019-01-10 08:58

One possible solution is to implement a fix server-side in the header, as suggested in this nice write-up by Aaron Layton. (All credit should go to him, and I'll paraphrase rather than plagiarize...)

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

"When Internet Explorer comes across this line it will change the engine that is being used to first Chrome Frame, if the plugin is installed, and then to Edge (the highest supported document mode of the browser)."

Steps:

  • Fix the page validation – This is achieved by simply removing the tag
  • Rendering speed – Instead of waiting for the browser to see the tag and then change modes we will send the correct mode upfront as a response header
  • Make sure that we only show the fix for Internet Explorer – We will just use some server side browser detection and only send it to IE

To add the header in PHP we can just add this to our page:

if (isset($_SERVER['HTTP_USER_AGENT']) &&
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        header('X-UA-Compatible: IE=edge,chrome=1');


Or you could add it to your .htaccess file like so:

<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</FilesMatch>


Link to original article, check comments for possible caveats. Also includes an implementation for C#.

Fix Bad value X-UA-Compatible once and for all

Hope this helps!

查看更多
该账号已被封号
5楼-- · 2019-01-10 09:02
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

See this article for a possible fix

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-10 09:10

I had the same issue and adding and to surround that entire line remedied the situation.

<!--[if IE]><meta http-equiv="x-ua-compatible" content="IE=9" /><![endif]-->
查看更多
淡お忘
7楼-- · 2019-01-10 09:11

Either X-UA-Compatible is not "standard" HTML (FSVO "standard" that involves appearing on a publicly editable wiki page referenced by the specification) or the Validator isn't up to date with the current status of that wiki.

At the time of writing (20130326) X-UA-Compatible appears on the wiki page under a section that states: "The following proposed extensions do not yet conform to all the registration requirements in the HTML spec and are therefore not yet allowed in valid documents." So the validator is correct to reject this value.

查看更多
登录 后发表回答