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!

John
  • 29,788
  • 18
  • 89
  • 130
šljaker
  • 7,294
  • 14
  • 46
  • 80
  • "IE9 visitors will see my website in Quirks mode"... are you sure about that? – Wesley Murch Nov 04 '11 at 14:12
  • 2
    Yes. Without that meta tag, default document mode is set to Quirks mode. I tested this on different computers. – šljaker Nov 04 '11 at 16:19
  • I guess I need to read more because I thought it was "IE9" mode by default. – Wesley Murch Nov 04 '11 at 16:32
  • this is a duplicate, please refer to: [is-it-legal-to-use-ie-specific-metatags-in-html5][1] [1]: http://stackoverflow.com/questions/2977590/is-it-legal-to-use-ie-specific-metatags-in-html5 – Eliran Malka Nov 05 '11 at 20:43
  • IE9 will use standards mode by default unless a comment is present before your DOCTYPE declaration, see here http://stackoverflow.com/questions/6529728/html5-doctype-putting-ie9-into-quirks-mode I can confirm that because I don't see my browser entering quirks mode with HTML5 doctype – mare Jun 30 '12 at 14:04

7 Answers7

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

GreenOrk
  • 121
  • 1
  • 2
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.

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • I'm using ASP.NET MVC 3. Could you please give me some code sample? Thanks! – šljaker Nov 04 '11 at 14:46
  • @šljaker - 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");` – Alohci Nov 05 '11 at 01:31
  • 2
    You can add this to the web.config system.Webserver > httpProtocol > customHeaders section as well. – ScottE Aug 03 '12 at 14:11
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

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
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.

Lea Cohen
  • 7,990
  • 18
  • 73
  • 99
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]-->
dangowans
  • 2,263
  • 3
  • 25
  • 40
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

mare
  • 13,033
  • 24
  • 102
  • 191
2

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

Okonomiyaki3000
  • 3,628
  • 23
  • 23