【问题标题】:HTML 5 w3c validationHTML 5 w3c 验证
【发布时间】:2011-12-21 22:59:04
【问题描述】:

我使用 validator.w3.org 验证了我的网站

报如下错误:

Line 5, Column 67: Bad value X-UA-Compatible for attribute http-equiv on element meta.
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >

如果我不包含那个 META 标签,那么所有 IE9 访问者都会在 Quirks 模式下看到我的网站,我想阻止这种情况。

任何帮助将不胜感激!

【问题讨论】:

  • “IE9 访问者会在 Quirks 模式下看到我的网站”...你确定吗?
  • 是的。如果没有该元标记,默认文档模式将设置为 Quirks 模式。我在不同的计算机上对此进行了测试。
  • 我想我需要阅读更多,因为我认为它默认是“IE9”模式。
  • 这是重复的,请参考:[is-it-legal-to-use-ie-specific-metatags-in-html5][1] [1]:stackoverflow.com/questions/2977590/…跨度>
  • IE9 将默认使用标准模式,除非您的 DOCTYPE 声明之前存在注释,请参阅此处stackoverflow.com/questions/6529728/… 我可以确认,因为我没有看到我的浏览器进入带有 HTML5 文档类型的怪癖模式跨度>

标签: html internet-explorer-9 w3c-validation


【解决方案1】:

您始终可以将 X-UA-Compatible 设置放入实际的 HTTP 标头中。具体操作方式取决于您使用的 Web 服务器,以及您使用的服务器端框架(如果有)。

【讨论】:

  • 我正在使用 ASP.NET MVC 3。你能给我一些代码示例吗?谢谢!
  • @šljaker - 我并不特别熟悉 ASP.NET MVC,但在 C# 中它类似于 Response.AppendHeader("X-UA-Compatible", "IE=edge,chrome=1");
  • 您也可以将其添加到 web.config system.Webserver > httpProtocol > customHeaders 部分。
【解决方案2】:

同样的问题,但我的解决方案是在我的 .htaccess 文件中添加以下行:

Header set X-UA-Compatible "IE=edge"

非常适合我...

【讨论】:

    【解决方案3】:

    你只需要接受这样一个事实,如果你想要 IE 支持,你需要放弃完美的验证分数。

    没关系,validity != quality

    【讨论】:

    • 你可以设置 这可能会保持有效性。
    • 根据this link,这没有按预期工作。
    【解决方案4】:

    解决方案非常简单,主题可以在功能模板中包含这个简单 只需打开 /templates/YOUR TEMPLATE/warp/systems/themes/head.php

    来自

    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;

    到

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

    【讨论】:

      【解决方案5】:

      对于使用PHP的人来说,通过PHP中的header函数传递这个参数的方式:

      header('X-UA-Compatible: IE=edge,chrome=1');
      

      这是一个post with code + explanation。

      【讨论】:

        【解决方案6】:

        对于使用 ASP.NET MVC 的人

        一种选择是在控制器/动作上使用动作过滤器。这确实会减慢服务器的响应速度,但我不知道确切的数字。但这是一种干净的方式:

        ///
        /// Represents an attribute that is used to add HTTP Headers to a Controller Action response.
        ///
        public class HttpHeaderAttribute : ActionFilterAttribute
        {
            ///
            /// Gets or sets the name of the HTTP Header.
            ///
            /// The name.
            public string Name { get; set; }
        
            ///
            /// Gets or sets the value of the HTTP Header.
            ///
            /// The value.
            public string Value { get; set; }
        
            ///
            /// Initializes a new instance of the  class.
            ///
            /// The name.
            /// The value.
            public HttpHeaderAttribute(string name, string value) {
                Name = name;
                Value = value;
            }
        
            public override void OnResultExecuted(ResultExecutedContext filterContext) {
                if(!filterContext.HttpContext.Response.Headers.AllKeys.Contains(Name, StringComparer.OrdinalIgnoreCase))
                    filterContext.HttpContext.Response.AppendHeader(Name, Value);
                base.OnResultExecuted(filterContext);
            }
        }
        

        但是,对我来说绝对最好和最干净的方法是使用web.config。将此代码放入&lt;system.webServer&gt;元素中:

        <httpProtocol>
          <customHeaders>
            <!-- 
                                    http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
                                    Uncomment to serve cross-domain ajax requests
        
                                    <add name="Access-Control-Allow-Origin" value="*" />
                                    -->
            <!-- 
                                    Force the latest IE version, in various cases when it may fall back to IE7 mode
                                    github.com/rails/rails/commit/123eb25#commitcomment-118920
                                    Use ChromeFrame if it's installed for a better experience for the poor IE folk 
                                    -->
            <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />
            <!-- 
                                    Allow cookies to be set from iframes (for IE only)
                                    If needed, uncomment and specify a path or regex in the Location directive 
        
                                    <add name="P3P" value="policyref=&quot;/w3c/p3p.xml&quot;, CP=&quot;IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&quot;" />
                                    -->
            <!-- A little extra security (by obscurity) -->
            <remove name="X-Powered-By" />
          </customHeaders>
        </httpProtocol>
        

        显然这只适用于 IIS7+。

        HTH

        【讨论】:

          【解决方案7】:

          您是否尝试过不在乎 HTML 验证器对您的代码的评价?这通常对我有用。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2018-07-16
            • 2017-04-13
            • 2020-04-26
            • 2016-08-07
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多