21

This is driving me insane.

No matter what I try, Internet Explorer is switching to IE7 Standards Document Mode. I have tried stripping my code back to nothing to try and get it to behave, using HTML5 boilet plate AND HTML5 reset (whose own site goes into Quirks Mode).

I have also added the meta tag that is supposed to force IE to it's latest version no matter what, but all that has done is made my mark-up invalid according to W3C.

This is what I have; what am I missing?

<!doctype html>

<!--[if IE 7 ]> <html class="ie7> <![endif]-->
<!--[if IE 8 ]> <html class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <p>Test text</p>        
</body>
</html>

EDIT

I have a solution found via a suggestion below. The suggestion didn't work, but it did lead me to an answer. This might not be 100% suitable for everyone since it imposes a class on the body tag rather than html, but it works for me and seems to work for IE.

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="css/style.css">
</head>
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->
<p>Test text</p>        
</body>
</html>
Josh Unger
  • 6,717
  • 6
  • 33
  • 55
Alan Shortis
  • 1,277
  • 3
  • 18
  • 35
  • This is working just fine in my IE9 on Windows7. It is showing that IE9 standards mode is the page default and the mode being used. Does your IE9 show the page default as IE7? – andyb Oct 11 '12 at 10:54
  • Is your site in the "intranet zone" in IE settings? – one.beat.consumer Feb 21 '13 at 00:32
  • just out of curiosity, were developer tools saying that the page default was IE9 standards but still using IE7? This is what's happening for me, I'm trying your solution but the bug isn't consistent so I'm not sure yet if it fixed it... – Sabrina Leggett Mar 18 '13 at 09:18

8 Answers8

10

from this thread

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

Community
  • 1
  • 1
Anoop
  • 23,044
  • 10
  • 62
  • 76
  • 2
    I tried what you suggested and unfortunately it didn't make any difference. HOWEVER, it did lead me to the answer. I am using conditional comments to impose a class on my `html` tag so I can adapt my CSS for older versions of IE. It turns out that conditional comments cannot be used before `head` so I simply moved my conditional comment to the body tag. It works fine and I still get to customise my CSS. THANK YOU. – Alan Shortis Oct 11 '12 at 11:03
  • @AlanShortis Please post this as an answer to your own question. It's the correct formal way. – Markus Unterwaditzer Oct 11 '12 at 11:10
  • @Markus Done. Thanks again for pointing me in the right direction. – Alan Shortis Oct 11 '12 at 11:22
  • @AlanShortis I think you already know but if you don't, You should also select your answer. – Anoop Oct 11 '12 at 11:24
  • @Shusl - I will, though I cannot do that for 2 days for some reason! – Alan Shortis Oct 11 '12 at 11:45
10

I have a solution found via an earlier suggestion. The suggestion didn't work, but it did lead me to an answer. This might not be 100% suitable for everyone since it imposes a class on the body tag rather than html, but it works for me and seems to work for IE.

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="css/style.css">
</head>
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->
<p>Test text</p>        
</body>
</html>

EDIT

I have actually stopped using the above and now add my IE specific classes to the html element, as suggested in HTML5BP.

Also note that you may want to remove chrome=1 from the meta tag as Chrome Frame is being killed off soon. No harm in keeping it though for those rare cases where someone is still using it though.

Another thing to check which I don't think has been mentioned is the status of what is probably the most irritating setting in IE - 'Display intranet sites in Compatibility View'. If you run a testing server with a name like http://mytestserver:8888 IE will think it's an intranet site and switch modes regardless of what you do in your document head.

This setting is enabled in my company's group policy as our ancient sharepoint intranet actually relies on it. Great for the old crap, but terrible for the new stuff which is actually going to adhere to standards.

Switch that f***er off in Tools > Compatibility View Settings and be prepared to switch to it manually if you have any legacy sites.

Alan Shortis
  • 1,277
  • 3
  • 18
  • 35
8

Sometimes IE behaves extra badly on intranet sites, forcing them into compatibility mode regardless of the <meta> line in the head. However, you can make the server send a header to brute-force IE to behave by adding the following to the web config:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=Edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>
st3inn
  • 1,556
  • 9
  • 17
  • Thanks for this - not the solution to this specific problem, but I do have some intranet work on the horizon and will make sure I use this. – Alan Shortis Oct 11 '12 at 11:07
3

Keep the

<!doctype html>

to be the first line of the page source, and the X-UA-Compatible meta tag must be tilte tag's adjacent next sibling.

<meta charset="utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
dorian
  • 31
  • 3
2

I was also having this issue with ie10 forcing IE7 standards mode for sites on localhost. Adding/using a virtualhost including a dot in its name (local.x) solved the issue.

Semra
  • 2,787
  • 28
  • 26
0

The link that Stuart posted worked for me as it related to the local website being set for compatibility mode. Once I removed the intranet website from the compatibility mode list, then the page went to the proper IE=9 mode according to the meta tag.

0

I've used the following to fix this problem when IE8 was rendering in IE7 Standards document mode despite all else I tried. Add this just before the doctype declaration:

<!--[if IE ]><![endif]-->

So the resulting HTML would look something like this:

<!--[if IE ]><![endif]-->
<!doctype html>
<!--[if IE 7]><html class="lt-ie8"><![endif]-->
<!--[if IE 8]><html class="lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->
<head>
    <title>Page title here</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

Someone else will have to comment on why this seems to work--it is a mystery to me.

Shawn
  • 8,374
  • 5
  • 37
  • 60