IE Compatibility mode cannot be disabled with Apac

2020-02-13 05:13发布

I am having a big issue trying to disable IE's Compatibility mode.

After much head banging, I have traced the issue down to whether the site is been served as Apache's default config, or as a virtual host.

I know this to be the case as when I access the site with the 'localhost' domain, everything is fine. As soon as I access the very same page via a domain configured in a virtual host - the site renders in Compatibility mode.

Can anyone please shed any light on this crazy issue???

Serving the site as the default host isn't an option.

  • Dean

2条回答
Fickle 薄情
2楼-- · 2020-02-13 05:39

When a web-site is being served on the local intranet, Internet Explorer will (by default) switch to IE7 compatible mode.

You can use the to disable this "IE7 on the intranet compatibility mode" by including the X-UA-Compatible response header to your page:

HTTP/1.1 200 OK
X-UA-Compatible: IE=8

You can also add the equivlent of an http response head to your page by including a meta http-equiv element to the HEAD> of your document. E.g.:

<!DOCTYPE html>
<html>
   <head>
   <title>Hello world!</title>
   <meta http-equiv="X-UA-Compatible" content="IE=9">
   </head>
<body>

</body>
</html>

Note: If you do include the header

| Header           | Value   |
|------------------|---------|
| X-UA-Compatible  | IE=10   |

to your html document, you must add it high enough in the HEAD before something else happens that locks in the document mode - and you're locked into IE7.

Wrong example 1

<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html lang="en">
<head>

meta elements belong inside the head element

Wrong example 2

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Hello, world!</title>
   <link rel="stylesheet" type="text/css" media="all" href="main-73c2257f2d.css" />
   <meta http-equiv="X-UA-Compatible" content="IE=8">

The X-UA-Compatible element must appear first in the head; except for title and other meta elements.

The X-UA-Compatible header isn't case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.

Wrong example 3

<!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=10">

The conditionals lock the browser into IE7 mode. Remove them.

Correct

<!doctype html>
<head>
   <title>Hello, world!</title>
   <meta http-equiv="X-UA-Compatible" content="IE=10">
查看更多
萌系小妹纸
3楼-- · 2020-02-13 05:40

Ah-ha!

From here (emphasis mine):

A large number of line-of-business websites are Internet Explorer 7 capable today. In order to preserve compatibility, Internet Explorer 8 ships with smart defaults based on zone evaluation. In the default state, all sites on the public internet display in Internet Explorer 8 Standards mode (Compatibility View off) and all intranet websites display in Internet Explorer 7 Standards mode (Compatibility View on).

...

If you navigate to sites on your local intranet like http://myPortal and http://sharepoint/sites/mySite, Internet Explorer 8 identifies itself with a User Agent string of ‘7’, Version Vector of ‘7’, and displays webpages that trigger standards mode in Internet Explorer 7 Standards mode. This combination allows webpages that worked correctly in Internet Explorer 7 to continue to do so in IE8.

I'm not commenting this. I'm sure this has some good real-world reasons, but I still have the urge to hit my head on the desk.

查看更多
登录 后发表回答