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?
19 Answers
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')
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.
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:
- The document mode
- 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.)
Try putting the following in the header:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Courtesy Paul Irish's HTML5 Boilerplate (but it works in XHTML Transitional, too).
I was able to override compatibility mode by specifying the meta tag as THE FIRST TAG in the head section, not just the first meta tag but as and only as the VERY FIRST TAG.
Thanks to @stefan.s for putting me on to it in your excellent answer. Prior to reading that I had:
THIS DID NOT WORK
<head>
<link rel="stylesheet" type="text/css" href="/qmuat/plugins/editors/jckeditor/typography/typography.php"/>
<meta http-equiv="x-ua-compatible" content="IE=9" >
moved the link tag out of the way and it worked
THIS WORKS:
<head><meta http-equiv="x-ua-compatible" content="IE=9" >
So an IE8 client set to use compatibility renders the page as IE8 Standard mode - the content='IE=9' means use the highest standard available up to and including IE9.
I had struggled with this issue and wanted to help provide a unique solution and insight.
Certain AJAX based frameworks will inject javascripts and stylesheets at the beginning of the <head>
and doing this seems to prevent the well-established meta tag solution from working properly. In this case I found that directly injecting into the HTTP response header, much like Andras Csehi's answer will solve the problem.
For those of us using Java Servlets however, a good way to solve this is to use a ServletFilter.
public class EmulateFilter implements Filter {
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletResponse response = ((HttpServletResponse)arg1);
response.addHeader("X-UA-Compatible", "IE=8");
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
We can resolve this problem in Spring-Apache-tomcat environment by adding one single line in RequestInterceptor method -
//before the actual handler will be executed
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {
// Some logic
// below statement ensures IE trusts the page formatting and will render it acc. to IE 8 standard.
response.addHeader("X-UA-Compatible", "IE=8");
return true;
}
Reference from - How to create filter and modify response header It covers how we can resolve this problem via a RequestInterceptor (Spring).
If you want your Web site to force IE 8 standards mode, then use this metatag along with a valid DOCTYPE:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
Note the "EmulateIE8" value rather than the plain "IE8".
According to IE devs, this should, "Display Standards DOCTYPEs in IE8 Standards mode; Display Quirks DOCTYPEs in Quirks mode. Use this tag to override compatibility view on client machines and force Standards to IE8 Standards."
more info on this IE blog post: http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx
This question is a duplicate of Force "Internet Explorer 8" browser mode in intranet.
The responses there indicate that it's not possible to disable the compatibility view (on the server side) - https://stackoverflow.com/a/4130343/24267. That certainly seems to be the case, as none of the suggestions I've tried have worked. In IE8 the "Browser Mode" gets set to Internet Explorer 8 Compatibility view no matter what kind of X-UA-Compatible header you send.
I had to do some special handling for IE7 and compatibility mode, which caused the browser to render using IE8 but report it was IE7, broke my code. This is how I fixed my code (I am aware this is a horrible hack and I should be testing for features not browser versions):
isIE8 = navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 8; if (!isIE8 && navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 7 && navigator.appVersion.indexOf("Trident") != -1) { // Liar, this is IE8 in compatibility mode. isIE8 = true; }
Add this inside your pages head tag (targeting the IE version you want):
<meta http-equiv="X-UA-Compatible" content="IE=8" />
Note, this will NOT change the fact that the browser says its in compatibility mode (called the browser mode), but the page will render in IE8 standards mode. If its STILL not rendering how you wish, its probably because you have javascript that is erroneously checking the I.E. version. See the following blog post to determine which property you should be keying off of because even if you set the meta X-UA-Compatible tag, the user agent string will still say MSIE 7.0.
In my case, for the fix I had to add a check for IE7 Compatibility mode. I did so using a simple javascript code:
//IE8 and later will have the word 'trident' in its user agent string.
if (navigator.userAgent.indexOf("Trident")>-1) { //do something }
For anyone else reading this looking to disable this via GPO for all users, this is the setting:
Computer Configuration/Administrative Templates/Windows Components/Internet Explorer/Compatibility View/Turn on Internet Explorer Standards Mode for Local Intranet
although the web.config edit fixed it for me.
Change the headers in .htaccess
BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
Found the solution to this problem here: https://github.com/h5bp/html5-boilerplate/issues/378
Stefan S' comment about the document mode versus browser mode were very pertinent for my problem.
I have the X-UA-Content meta data in the page, but I was client-side testing the browser version via navigator.appVersion
. This test does not reflect the meta data because it is giving the browser mode not the document mode.
The answer for me was to test the document.documentMode
something like:
function IsIE(n)
{
if (navigator.appVersion.indexOf("MSIE ") == -1) return false;
var sDocMode = document.documentMode;
return (isFinite(sDocMode) && sDocMode==n);
}
Now, my meta X-UA-Content tag reflects in my browser test.
Why do I do such a frowned-on thing as test the browser? Speed. Various of my jQuery add-ins, like tablesorter are just too slow on IE6/7, and I want to turn them off. I am not sure that testing for browser features can help me solve this otherwise.