By default IE8 forces intranet websites into compatibility mode. I tried changing the meta header to IE8, but it doesn't acknowledge the meta header and just uses the browser setting. Does anyone know how to disable this?


Solution 1:

It is possible to override the compatibility mode in intranet.

For IIS, just add the below code to the web.config. Worked for me with IE9.

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

Equivalent for Apache:

Header set X-UA-Compatible: IE=Edge

And for nginx:

add_header "X-UA-Compatible" "IE=Edge";

And for express.js:

res.set('X-UA-Compatible', 'IE=Edge')

Solution 2:

Michael Irigoyen is correct BUT it is a little more complicated...

if you are using the wonderful boilerplate by Paul Irish then you will have something like the following:-

<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

This will NOT work as expected and force in IE into compatibility mode in an Intranet environment if you have the "Display intranet sites in compatibility view" checked. You need to remove the conditional IE comments to prevent Intranet compatibility mode.

So the following code will work:

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Basically if you trigger conditional IE comments before the <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> statement then you will be forced into compatibility mode in an Intranet environment if you are running IE9 with the default settings.

UPDATE — ADDITIONAL INFO: But note that there is a trick that will make the HTML5 boilplate work:

Add an emtpy, conditional comment before the DOCTYPE. And note as well, that when you do that, then you can also add conditional comments around the X-UA-Compatible directive, making the page HTML5-valid as well. So for instance:

<!--[if HTML5]><![endif]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

A blog post that was inspired by the first part of this answer, has more detail. And by the way: As mentioned in that blog post, one can also replace the conditional comment before the DOCTYPE with a semi conditional comment with no condition: <!--[]-->. Thus, like so:

<!--[]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

But note that the latter variant (<--[]--><!DOCTYPE html>) will, as explained e.g by this answer to another question, activate the well know problem that it — for legacy IE versions without support for the X-UA-Compatioble (read: for IE7 and IE6) — bring the browser into into quirks-mode.

Solution 3:

If you pull down the "Tools" menu and choose "Compatibility View Settings" On that dialog at the bottom is a setting "Display intranet sites in compatibility mode". If you uncheck this that should resolve the problem and IE will use the mode based on the DOCTYPE.

Solution 4:

There is a certain amount of confusion in the answers to this this question.

The top answer is currently a server-side solution which sets a flag in the http header and some comments are indicating that a solution using a meta tag just doesn't work.

I think this blog entry gives a nice overview of how to use compatibility meta information and in my experience works as described: http://blogs.msdn.com/b/cjacks/archive/2012/02/29/using-x-ua-compatible-to-create-durable-enterprise-web-applications.aspx

The main points:

  • setting the information using a meta tag and in the header both works
  • The meta tag takes precedence over the header
  • The meta tag has to be the first tag, to make sure that the browser does not determine the rendering engine before based on heuristics

One important point (and I think lots of confusion comes from this point) is that IE has two "classes" of modes:

  1. The document mode
  2. The browser mode

The document mode determines the rendering engine (how is the web page rendered).

The Browser Mode determines what User-Agent (UA) string IE sends to servers, what Document Mode IE defaults to, and how IE evaluates Conditional Comments.

More on the information on document mode vs. browser mode can be found in this article: http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx?Redirected=true

In my experience the compatibility meta data will only influence the document mode. So if you are relying on browser detection this won't help you. But if you are using feature detection this should be the way to go.

So I would recommend using the meta tag (in the html page) using this syntax:

<meta http-equiv="X-UA-Compatible" content="IE=9,10" ></meta>

Notice: give a list of browser modes you have tested for.

The blog post also advices against the use of EmulateIEX. Here a quote:

That being said, one thing I do find strange is when an application requests EmulateIE7, or EmulateIE8. These emulate modes are themselves decisions. So, instead of being specific about what you want, you’re asking for one of two things and then determining which of those two things by looking elsewhere in the code for a DOCTYPE (and then attempting to understand whether that DOCTYPE will give you standards or quirks depending on its contents – another sometimes confusing task). Rather than do that, I think it makes significantly more sense to directly specify what you want, rather than giving a response that is itself a question. If you want IE7 standards, then use IE=7, rather than IE=EmulateIE7. (Note that this doesn’t mean you shouldn’t use a DOCTYPE – you should.)