Html 元素元上的 http-equiv 属性值 X-UA-Compatible

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14198594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:47:28  来源:igfitidea点击:

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

htmlvalidationx-ua-compatible

提问by Randomblue

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

我使用了与metaHTML5 Boilerplate相同的东西,W3C HTML 验证器抱怨:

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

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

元素元上的属性 http-equiv 的 X-UA-Compatible 值错误。

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

What is wrong with this metatag?

这个meta标签有什么问题?

采纳答案by Quentin

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

X-UA-Compatible 不是“标准”HTML(FSVO“标准”,涉及出现在规范引用的可公开编辑的 wiki 页面上),或者 Validator 未与该 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.

在撰写本文时 (20130326) X-UA-Compatible 出现在 wiki 页面的一个部分下,该部分指出:“以下提议的扩展尚未符合 HTML 规范中的所有注册要求,因此尚未允许在有效文件。” 所以验证器拒绝这个值是正确的。

回答by Matthew Haeck

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”标签中。

<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->

回答by D.Alexander

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

一种可能的解决方案是在标头中实现修复服务器端,正如Aaron Layton在这篇不错的文章中所建议的那样。(所有功劳都应该归功于他,我将改述而不是抄袭......)

<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)."

“当 Internet Explorer 遇到这条线时,它会将正在使用的引擎更改为第一个 Chrome Frame(如果安装了插件),然后更改为 Edge(浏览器支持的最高文档模式)。”

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
  • 修复页面验证 - 这可以通过简单地删除标签来实现
  • 渲染速度——我们将预先发送正确的模式作为响应头,而不是等待浏览器看到标签然后更改模式
  • 确保我们只显示 Internet Explorer 的修复程序——我们将只使用一些服务器端浏览器检测并将其发送到 IE

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

要在 PHP 中添加标题,我们可以将其添加到我们的页面中:

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:


或者你可以像这样将它添加到你的 .htaccess 文件中:

<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#.


链接到原始文章,检查评论以了解可能的警告。还包括 C# 的实现。

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

一劳永逸地修复错误值 X-UA-Compatible

Hope this helps!

希望这可以帮助!

回答by Faysal Haque

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

See this article for a possible fix

请参阅本文以获取可能的修复

回答by user1508429

.. may this be a good answer?

..这可能是一个很好的答案吗?

Set HTTP Header with PHP:

使用 PHP 设置 HTTP 标头:

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

这不是我自己的作品,但我希望它对其他人也有用。

回答by darcyparker

If you download/build the validator src code, you can add support yourself.

如果您下载/构建验证器 src 代码,您可以自己添加支持。

Add the following to a file such as html5-meta-X-UA-Compatible.rnc) Then include it in html5full.rnc.

将以下内容添加到文件中,例如html5-meta-X-UA-Compatible.rnc) 然后将其包含在html5full.rnc.

I did this and it works nicely for validating.

我这样做了,它非常适合验证。

meta.http-equiv.X-UA-Compatible.elem =
  element meta { meta.inner & meta.http-equiv.X-UA-Compatible.attrs }
  meta.http-equiv.X-UA-Compatible.attrs =
    ( common.attrs.basic
      & common.attrs.i18n
      & common.attrs.present
      & common.attrs.other
      & meta.http-equiv.attrs.http-equiv.X-UA-Compatible
      & meta.http-equiv.attrs.content.X-UA-Compatible
      & ( common.attrs.aria.role.presentation
        | common.attrs.aria.role.menuitem
        )?
    )
    meta.http-equiv.attrs.http-equiv.X-UA-Compatible = attribute http-equiv {
      xsd:string {
        pattern = "X-UA-Compatible"
      }
    }
    meta.http-equiv.attrs.content.X-UA-Compatible = attribute content {
      xsd:string {
        pattern = "IE=((edge)|(EmulateIE(7|8|9|10))|7|8|9|10|11)(,chrome=(1|0))?"
      }
    }

common.elem.metadata |= meta.http-equiv.X-UA-Compatible.elem

回答by bharat

Please remove ,chrome=1from meta tag it will working fine. With validator:

,chrome=1从元标记中删除它会正常工作。使用验证器:

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

回答by cinemafunk

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]-->