HTML 5 w3c 验证

发布于 2024-12-13 19:30:12 字数 324 浏览 2 评论 0原文

我使用 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 模式下看到我的网站,我想防止这种情况发生。

任何帮助将不胜感激!

I validated my website using validator.w3.org

It reported the following error:

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

If I don't include that META tag, than all IE9 visitors will see my website in Quirks mode, and I want to prevent that.

Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

抹茶夏天i‖ 2024-12-20 19:30:12

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

You could always put the X-UA-Compatible setting into the actual HTTP headers instead. How you do that depends on the web server you are using, and what, if any, server-side framework you are using.

甜心小果奶 2024-12-20 19:30:12

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

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

对我来说效果很好...

Same problem here, but my solution is to add the following line to my .htaccess file:

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

Works great for me...

殤城〤 2024-12-20 19:30:12

您必须接受这样一个事实:如果您想要 IE 支持,则需要放弃完美的验证分数。

不过没关系,有效性!=质量

You'll just have to accept the fact that if you want IE support, you'll need to give up perfect validation score.

It's alright though, validity != quality

回忆那么伤 2024-12-20 19:30:12

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

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

这里是aa 带有代码+解释的帖子

For people using PHP, the way to pass this parameter through the header function in PHP:

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

Here is a a post with code + explanation.

执笔绘流年 2024-12-20 19:30:12

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

只需从

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

The solution is very simple and theme can include this easy in feature templates
just open /templates/YOUR TEMPLATE/warp/systems/themes/head.php

from

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

to

<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->
醉殇 2024-12-20 19:30:12

对于使用 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。将此代码放入 元素中:

<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="/w3c/p3p.xml", CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"" />
                            -->
    <!-- A little extra security (by obscurity) -->
    <remove name="X-Powered-By" />
  </customHeaders>
</httpProtocol>

显然这仅适用于 IIS7+。

华泰

For guys using ASP.NET MVC

One option is to use Action Filter on controllers/actions. This does slow down responses from the server a bit but I don't know the exact numbers. But it's a clean way to do it:

///
/// 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);
    }
}

However, the absolutely best and cleanest way for me is using web.config. Put this code into <system.webServer> element:

<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="/w3c/p3p.xml", CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"" />
                            -->
    <!-- A little extra security (by obscurity) -->
    <remove name="X-Powered-By" />
  </customHeaders>
</httpProtocol>

Obviously this only works in IIS7+.

HTH

挽袖吟 2024-12-20 19:30:12

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

Have you tried not giving a damn what HTML validators say about your code? That usually works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文