Override intranet compatibility mode IE8

2018-12-31 09:53发布

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条回答
与君花间醉酒
2楼-- · 2018-12-31 10:22

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')
查看更多
流年柔荑漫光年
3楼-- · 2018-12-31 10:24

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.

查看更多
浅入江南
4楼-- · 2018-12-31 10:24

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;
}
查看更多
骚的不知所云
5楼-- · 2018-12-31 10:27

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 }
查看更多
笑指拈花
6楼-- · 2018-12-31 10:28

Our system admin resolved this issue by unchecking the box globally for our organization. Users did not even need to log off.

enter image description here

查看更多
栀子花@的思念
7楼-- · 2018-12-31 10:28

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

查看更多
登录 后发表回答