HTML 5 w3c validation
Asked Answered
T

7

23

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!

Tijerina answered 4/11, 2011 at 11:33 Comment(5)
"IE9 visitors will see my website in Quirks mode"... are you sure about that?Visage
Yes. Without that meta tag, default document mode is set to Quirks mode. I tested this on different computers.Confess
I guess I need to read more because I thought it was "IE9" mode by default.Visage
this is a duplicate, please refer to: [is-it-legal-to-use-ie-specific-metatags-in-html5][1] [1]: #2978090Uppercase
IE9 will use standards mode by default unless a comment is present before your DOCTYPE declaration, see here #6530228 I can confirm that because I don't see my browser entering quirks mode with HTML5 doctypeUnion
B
12

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.

Babs answered 4/11, 2011 at 14:10 Comment(3)
I'm using ASP.NET MVC 3. Could you please give me some code sample? Thanks!Confess
@Tijerina - I'm not familiar with ASP.NET MVC specifically, but in C# it's along the lines of Response.AppendHeader("X-UA-Compatible", "IE=edge,chrome=1");Babs
You can add this to the web.config system.Webserver > httpProtocol > customHeaders section as well.Postdiluvian
O
12

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

Outlawry answered 5/6, 2012 at 18:41 Comment(0)
M
8

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

Mither answered 4/11, 2011 at 11:35 Comment(2)
you can set <!--[if IE]> xua stuff <![endif]--> this might preserve validity.Tachyphylaxis
According to this link, this is not working as expected.Sophia
S
4

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.

Spae answered 26/12, 2012 at 8:5 Comment(0)
N
4

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]-->
Nocuous answered 21/11, 2013 at 3:30 Comment(0)
U
2

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=&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>

Obviously this only works in IIS7+.

HTH

Union answered 30/6, 2012 at 14:16 Comment(0)
O
2

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

Ostium answered 21/10, 2014 at 0:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.