X-UA-Compatible is set to IE=edge, but it still doesn't stop Compatibility Mode
Asked Answered
S

18

254

I am quite confused. I should be able to set

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

and IE8 and IE9 should render the page using the latest rendering engine. However, I just tested it, and if Compatibility Mode is turned on elsewhere on our site, it will stay on for our page, even though we should be forcing it not to.

How are you supposed to make sure IE does not use Compatibility Mode (even in an intranet)?

FWIW, I am using the HTML5 DocType declaration (<!doctype html>).

Here are the first few lines of the page:

<!doctype html> 
<!--[if lt IE 7 ]> <html lang="en" class="innerpage no-js ie6"> <![endif]--> 
<!--[if IE 7 ]>    <html lang="en" class="innerpage no-js ie7"> <![endif]--> 
<!--[if IE 8 ]>    <html lang="en" class="innerpage no-js ie8"> <![endif]--> 
<!--[if (gte IE 9)|!(IE)]><!--> 
<html lang="en" class="innerpage no-js"> 
<!--<![endif]--> 
    <head> 
        <meta charset="ISO-8859-1" /> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

EDIT: I just learned that the default setting on IE8 is to use IE7 compatibility mode for intranet sites. Would this override the X-UA-Compatible meta tag?

Silber answered 27/5, 2011 at 19:7 Comment(3)
I'm having this problem too with some of my users, did you ever figure this out? My app isn't intranet though. And only like 20% of the users get it, strangely.Tammy
This might be the result of your funny <html> tag markup (the <!--[if lt IE 7 ]> stuff). Try removing it and see if it works. See this SO question #10683327Radioactivate
@SundayIronfoot FYI, the funny <html> tag markup you refer to is conditional IE comments that is used to add a CSS class to the <html> element for the appropriate version of IE (if applicable) so you can style things differently as needed for the IE versions by simply prefixing your style declaration with ".ie7 ", like: .ie7 p { width: 200px; } ... it's a cleaner work around for rendering issues in older IE versions than having to use some of the CSS hacks like *width or _width. Browsers other than IE will ignore it and just use the basic one.Ringmaster
R
263

If you need to override IE's Compatibility View Settings for intranet sites you can do so in the web.config (IIS7) or through the custom HTTP headers in the web site's properties (IIS6) and set X-UA-Compatible there. The meta tag doesn't override IE's intranet setting in Compatibility View Settings, but if you set it at the hosting server it will override the compatibility.

Example for web.config in IIS7:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=EmulateIE8" />
      </customHeaders>
    </httpProtocol>
</system.webServer>

Edit: I removed the clear code from just before the add; it was an unnecessary oversight from copying and pasting. Good catch, commenters!

Ringmaster answered 18/2, 2012 at 5:47 Comment(12)
Just a note though... If you're developing using the built-in Visual Studio development web server (a.k.a. Cassini), then this won't work because Cassini doesn't honor the <system.webServer> section of the web.config. So, for development, use IIS Express instead.Borchert
What's the reason for the <clear />? What custom headers are cleared by this?Asthenosphere
The clear seems to remove the <urlCompression...> rule at least for me. That rule does gzipping, which I do want so I commented out the clear. Any further information would be lovely.Talavera
I removed the 'clear' - good catch, it was an unnecessary line from copying and pasting from my implementation.Ringmaster
PHP: <?php header('X-UA-Compatible: IE=edge'); ?>Toponym
@Toponym Need your help! Could you tell me where to add it? I am using PHP. Should I add it before <!DOCTYPE html> or after <head><title></title>. Thanks!Baird
Headers need to be set before any HTML is sent to the browser. So before doctype.Toponym
We have apache servers, what do I need to do?Sjoberg
rather than using <clear /> should you do <remove name="X-UA-Compatible" /> prior to the add?Tinatinamou
Dennis Ritchie bless you!Roussel
clear is needed in other cases where an add might cause an error if the same item is added in a parent config.Casanova
Just as a note: in Java and Tomcat I had to implement a filter and map it to Faces Servlet. On this filter, at he begining of the doFilter method I added: response.addHeader("X-UA-Compatible", "IE=edge");Camilacamile
K
186

Server Side solution is the recommended one, as @TimmyFranks proposed in his answer, but if one needs to implement the X-UA-Compatible rule on the page level, please read the following tips, to benefit from the experience of the one who already got burned


The X-UA-Compatible meta tag must appear straight after the title in the <head> element. No other meta tags, css links and js scripts calls can be placed before it.

<head>
    <title>Site Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <script type="text/javascript" src="/jsFile.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
    <link rel="shortcut icon" href="/apple-touch-icon.png" />
</head>

If there are any conditional comments in the page (lets say located in the <html>), they must be placed under, after the <head>.

// DON'T: place class inside the HTML tag 
<!--[if gt IE 8]><!--> 
    <html class="aboveIe8"> 
<!--<![endif]-->

// DO: place the class inside the BODY tag
<!--[if gt IE 8]><!--> 
    <body class="aboveIe8"> 
<!--<![endif]-->

Html5BoilerPlate's team wrote about this bug - http://h5bp.com/i/378 They have several solutions.

Regarding Intranet & Compatibility view, there're settings when you go to tools > Compatibility view settings.

Compatibility view settings

Katzenjammer answered 8/3, 2012 at 20:33 Comment(8)
I have tried 4 or 5 other answers on Stack Overflow, and only this specific combination worked for me. For anyone using WordPress and an SEO plugin, be careful about the plugin rewriting the <title> in another location. Edit: Added WordPress commentMandrill
X-UA-Compatible should appear as early as possible, probably after charset. I don't think it's true that it "must appear straight after the title".Jordans
This recommendation is a result of suffering under IE. Been gained by blood. Who says IE following guidelines?Katzenjammer
Wow, this worked for me and having my meta tags right after the title tag is what did the trick. Wish it weren't so archaic to make this work...Egger
The X-UA-Compatible meta tag can appear after title, base and any other meta tags without losing its effect. This is what I tested in IE8. No conditional comments can be put before it, though.Eliott
oh my god, internet explorer 10 still suffers from this... it's thanks to your post I figured out whats wrong...Humorist
Placing the conditional comments after the <html> tag works for me along with the meta tags! Thanks @KatzenjammerBurdelle
Did not work on IE11 with: <meta http-equiv="X-UA-Compatible" content="IE=edge" />Gertrudis
F
37

Note that if you are serving it from PHP, you can use the following code to fix it as well.

header("X-UA-Compatible: IE=Edge");
Fiction answered 9/4, 2012 at 18:32 Comment(7)
This works better than adding the meta tag, since it passes W3C validation using this method and is much easier than an .htaccess hack.Byandby
I tried everything else, and this was what finally worked. Thank you.Ideography
For those on WordPress, this may help: codex.wordpress.org/Plugin_API/Action_Reference/send_headersDemmer
This works a lot better also when a huge site is built depending on <!--[if lt IE 7 ]> <html>... ! THANK YOU! You are god sent!!Benedetta
For anyone using PHP and coming here from google, THIS IS THE CORRECT ANSWER because it's the best solution out there! Send the headers before any content!Jardiniere
Should this - header("X-UA-Compatible: IE=Edge"); be added straight after the title in the <head> element?Baird
@Baird - Any header's sent by PHP MUST happen prior to sending any output to the page, that is before any HTML or data is output by PHP.Fiction
S
26

As it turns out, this has to do with Microsoft's "intelligent" choice to make all intranet sites force to compatibility mode, even if X-UA-Compatible is set to IE=edge.

Silber answered 18/7, 2011 at 17:15 Comment(7)
That's not true. The X-UA-Compatible will override the compatibility mode setting. However, sometimes using the meta tag does not work because the mode has already been set by the time it encounters it. This is why I use the HTML header version, so the browser can enable standards mode early in the process.Unship
Adding to Mystere Man's comment, you can override it from the hosting server using the web.config or the custom http headers in IIS. See my post above for details.Ringmaster
I have tried this multiple times and it does not override all intranet sites forced to comparability mode.Dimitris
@Mystere Man: Define sometimes as whenever the page is in an iframe, where the parent document doesn't define XUA-COMPAT, and the document mode is inherited from the parent page (another very intelligent MS choice).Boutis
@Kerrick: This is not the correct answer. See the one below this answered by tj111 for the correct answer.Jardiniere
When the user has turned on Compatibility View you cannot override it from the server or html page. This value is saved in the Windows registry and cannot be accessed via a page. If you think about it it would be dangerous to manipulate an app from a web site.Koralle
@ErikFunkenbusch I can assure you that the X-UA-Compatibility flag does not override a group policy compatibility mode.Aludel
T
9

I also got the same issue of IE9 rendering in IE7 Document standards for local host. I tried many conditional comments tags but unsuccesful. In the end I just removed all conditional tags and just added meta tag immediatly after head like below and it worked like charm.

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

Hope it helps

Twila answered 30/8, 2013 at 8:14 Comment(0)
C
8

Even if you have unchecked the "Display intranet sites in Compatibility View" option, and have the X-UA-Compatible in your response headers, there is another reason why your browser might default to "Compatibility View" anyways - your Group Policy. Look at your console for the following message:

HTML1203: xxx.xxx has been configured to run in Compatibility View through Group Policy.

Where xxx.xxx is the domain for your site (i.e. test.com). If you see this then the group policy for your domain is set so that any site ending in test.com will automatically render in Compatibility mode regardless of doctype, headers, etc.

For more information, please see the following link (explains the html codes): http://msdn.microsoft.com/en-us/library/ie/hh180764(v=vs.85).aspx

Contribute answered 24/7, 2013 at 15:42 Comment(0)
K
5

As NEOSWF points out above, the Paul Irish conditional comments stops the meta tag having any affect.

There are several fixes all here (http://nicolasgallagher.com/better-conditional-classnames-for-hack-free-css/)

These include:

Adding two HTML classes, using server headers and adding a conditional comment above the doctype.

On my latest project I decided to remove the Paul Irish conditional comments. I didn't like the idea of adding anything before the html without doing LOTS of testing first and it's nice to see what has been set just by looking at the HTML.

In the end I surrounded a div straight after the body and used conditional comments eg

  <!--[if IE 7]><div class="ie7"><!--<![endif]-->
  ... regular body stuff
  <!--[if IE 7]></div><!--<![endif]-->

I could have done this around the body but its more difficult with CMSs like Wordpress.

Obviously its another DIV inside the markup, but its only for older browsers.

I think it could be a per project based decision though.

I've also read something about the charset meta tag needing to come in the first 1024 bytes so this ensures that.

Sometimes the simplest, easiest to read ideas are the best and its definitely worth thinking about! Thanks to the 6th comment on the link above for pointing this out.

Kg answered 16/1, 2013 at 11:13 Comment(0)
T
5

X-UA-Compatible will only override the Document Mode, not the Browser Mode, and will not work for all intranet sites; if this is your case, the best solution is to disable "Display intranet sites in Compatibility View" and set a group policy setting to specify which intranet sites need compatibility mode.

Tb answered 9/9, 2013 at 18:55 Comment(0)
A
5

I added the following to my htaccess file, which did the trick:

BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
Archival answered 10/9, 2013 at 8:27 Comment(2)
this works when intranet is set to compatibility. took me long time to find something that will work. specially when you search and everything is iis relatedFiery
This is awesome. I didn't know you could send headers with .htaccessBarquisimeto
T
3

Additionally, X-UA-Compatible must be the first meta tag in the head section

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

By the way, the correct order or the main head tags are:

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <title>Site Title</title>
    <!-- other tags -->
</head>

This way

  1. we set the render engine to use before IExplorer begins to process
  2. the document then we set the encoding to use for all browser
  3. then we print the title, which will be processed with the already defined encoding.
Trisomic answered 6/3, 2014 at 19:3 Comment(3)
Actually, the CHARSET should precede the X-UA-Compatible. See blogs.msdn.com/b/ieinternals/archive/2011/07/18/…Grasping
It doesn't have to be first, but it does need to be near the top. It can follow title (and charset, as Eric noted), but that's about it.Babu
in my case on nginx it will only work if the X-UA-Compatible-tag is the first in the head sectionAlcheringa
S
2

Timmy Franks had it right for me. We just had the issue today where the client had IE8 company-wide, and it was forcing the site we wrote for their intranet into compatibility mode. Setting "IE-Edge" seemed to fix it.

<httpProtocol>
  <customHeaders>
    <clear />
    <add name="X-UA-Compatible" value="IE=Edge" />
  </customHeaders>
</httpProtocol>
Subalternate answered 29/3, 2012 at 20:59 Comment(0)
P
2

For Nginx,

add_header "X-UA-Compatible" "IE=Edge,chrome=1";

ref : https://github.com/h5bp/server-configs/commit/a5b0a8f736d68f7de27cdcb202e32975a74bd2c5

Peri answered 20/6, 2016 at 6:32 Comment(0)
T
1

IE 11 doesn't allow you to override the browser compatibility view setting anymore by sending the header...

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

It appears the only way to force the browser to not use compatibility view is to have the user disable it in their browser. Ours is an Intranet site, and the default IE option is to use compatibility view for Intranet sites. What a pain!

We were able to prevent the need for the user to change their browser settings for users of IE 9 and 10, but it no longer works in IE 11. Our IE users are switching to Chrome, where this is not a problem, and never has been.

Timelag answered 27/11, 2013 at 17:40 Comment(7)
It's not that it doesn't allow it, IE11 doesn't support other Compatibility Modes other than edge. Link to official documentation. That means we don't have to use that meta tag to hide the CM button on the address bar anymore.Eclecticism
Untrue: IE11 still supports all legacy Compatibility Modes.Grasping
@EricLaw, is EricP's answer correct (that IE11 changes the behavior for the X-UA-Compatible HTTP header)?Rutile
@EricP, did you try the HTTP header, or only the <meta> tag version?Rutile
@MatthewFlaschen: No, EricP is incorrect, as is Wallace Sidhree (although to be fair to Wallace, MSDN doesn't explain what they mean by "deprecated"). What changed in IE11 is that there's no visible "Compatibility View" button at all (technet.microsoft.com/en-us/library/dn321449.aspx) but the X-UA-Compatible declarations are still respected.Grasping
In the MSDN documentation, "deprecated" means the feature is still available in the binaries, but there's no guarantee it won't be pulled soon. You're strongly encouraged to update things to alternate solutions. "Obsolete" means the feature is no longer supported by the binaries and you must update things to use alternate techniques. As an example: conditional comments were deprecated as of IE10. As of IE11, they're obsolete. Also, starting with IE11, legacy document modes and supported only for IE on the desktop. The, er, "Windows store experience" of IE supports only edge mode.Babu
I tried on IE11 as well, with the meta below and it did not work. Also with other IE versions etc. <meta http-equiv="X-UA-Compatible" content="IE=edge" />Gertrudis
C
1

I was able to get around this loading the headers before the HTML with php, and it worked very well.

<?php 
header( 'X-UA-Compatible: IE=edge,chrome=1' );
header( 'content: width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' );
include('ix.html');
?> 

ix.html is the content I wanted to load after sending the headers.

Charged answered 10/6, 2014 at 20:40 Comment(0)
Y
1

I was experiencing the same issue in IE11. None of these answers solved my issue. After digging a bit, I noticed that the browser was running in Enterprise mode. (verify by hitting F12 and click the emulation tab, look for browser profile dropdown) The setting was locked, not allowing me to change the setting.

I was able to change the profile to Desktop after deleting CurrentVersion from the following registry key:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode

After changing the mode to Desktop the answers on this post will work.

Yoheaveho answered 24/3, 2017 at 14:4 Comment(0)
A
1

When your browser opens with Compatibility Modes, even you remove and turn off all compability modes configuration from your web browser and Local Group Policy Editor, you can try to disable from register key.

This also happen to me on using domain and sub-domain to connect server side. The machine is restricted to open in compability mode for all sub-domain.

DISABLE COMPABILITY MODE FOR INTRANET

HKEY_LOCAL_MACHINE - SOFTWARE - Policies - Microsoft - Internet Explorer - BrowserEmulation -> IntranetCompalityMode Value should be 0 (zero). And also remove existing domain name from PolicyList.

Otherwise, you can add a new value (DWORD) that contain 0 (zero) value data.

Avigdor answered 24/10, 2017 at 9:15 Comment(0)
Y
0

I had the same issue after trying many combination I had this working note I have compatibility checked for intranet

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<head runat="server">
Yardage answered 26/6, 2013 at 7:39 Comment(0)
L
0

If you are using LAMP stack, then add this into your .htaccess file in your web root folder. No need to add it to every PHP file.

<IfModule mod_headers.c>
    Header add X-UA-Compatible "IE=Edge"
</IfModule>
Lophophore answered 3/7, 2013 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.