{"id":2222,"date":"2012-08-15T22:06:04","date_gmt":"2012-08-15T22:06:04","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=2222"},"modified":"2012-08-15T22:10:08","modified_gmt":"2012-08-15T22:10:08","slug":"preventing-internet-explorer-from-using-compatibility-view","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=2222","title":{"rendered":"Preventing Internet Explorer from using Compatibility View"},"content":{"rendered":"<p>I&#8217;ve had some trouble with Internet Explorer recently. <\/p>\n<p>I was making a new web tool which looked fine in all browsers. Except Internet Explorer, where it looked a bit squiffy. <\/p>\n<p>Internet Explorer has &#8220;Compatibility View&#8221;. Compatibility View makes IE behave like the older versions of Internet Explorer, the ones before Microsoft started paying more attention to web standards. <\/p>\n<p>It makes sense &#8211; there are a lot of websites out there that were written to render well on old versions of Internet Explorer, and Microsoft needed to make the move to standards compliance in a way that doesn&#8217;t break all of them. <\/p>\n<p>The problem is, Compatibility View can be a little&#8230; insistent. <\/p>\n<p>It kept turning on, even though I didn&#8217;t want it, even though my site worked fine in new shiny standards mode, and looked horribly broken in Compatibility View. <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/dalelane.co.uk\/blog\/post-images\/120815-compat.png\" style=\"border: 1px solid black\"\/><\/p>\n<p>You can manually disable it, but I don&#8217;t want to have to make users do that. As the web developer, I want to be able to disable it &#8211; to tell IE that I want the site to be rendered in standards mode. <\/p>\n<p>It was a bit fiddly. Here&#8217;s how I did it. <\/p>\n<p><!--more--><strong>Specify a DOCTYPE<\/strong> that will let IE know the site is all new and groovy<br \/>\nI used <code>&lt;!DOCTYPE html&gt;<\/code><\/p>\n<p>It has to the first thing in the page, <strong>before anything else, even spaces or line breaks<\/strong>. Because of some comments and blank lines in my JSP, I had some blank lines before the &lt;!DOCTYPE html&gt; line, and Internet Explorer doesn&#8217;t notice it then. <\/p>\n<p>Start with &lt;!DOCTYPE html&gt; and it shows IE this isn&#8217;t a legacy site. <\/p>\n<p>But IE sometimes kept switching back into Compatibility View. <\/p>\n<p>There is <strong>a META tag you can put in the HEAD<\/strong> of your HTML to explicitly tell IE which mode to use.<br \/>\nI used <code>&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=9; IE=8; IE=7; IE=EDGE\" \/&gt;<\/code><\/p>\n<p>There is a small undocumented-feature \/ bug with this, too. <\/p>\n<p>It only works if this is the first tag after <code>&lt;HEAD&gt;<\/code>. I originally had this after a bunch of other META tags, but Internet Explorer doesn&#8217;t notice it then. But if you <strong>make it the first tag in the document head<\/strong>, IE will spot it. <\/p>\n<p>That works&#8230; most of the time. <\/p>\n<p>Unless IE thinks that the site is on the Intranet. Then it overrides the META tag instruction, and uses Compatibility View anyway. <\/p>\n<p>Why?!<\/p>\n<p>But it&#8217;s okay &#8211; there is <strong>an HTTP header<\/strong> that you can use to override the override. You can include it in your server response to tell IE that you definitely, positively, want it to stop buggering about and just use the non-ancient rendering mode. <\/p>\n<p><code>X-UA-Compatible : IE=edge<\/code><\/p>\n<p>I added a filter to set this header in my responses when serving HTML. <\/p>\n<p>Finally, it seems to work. <\/p>\n<p>Any one of these steps seems to make IE stay in standards mode some of the time. As far as I can tell, you need to do all of them, exactly right, to get IE to behave all of the time. <\/p>\n<p>That was a good use of a few hours(!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had some trouble with Internet Explorer recently. I was making a new web tool which looked fine in all browsers. Except Internet Explorer, where it looked a bit squiffy. Internet Explorer has &#8220;Compatibility View&#8221;. Compatibility View makes IE behave like the older versions of Internet Explorer, the ones before Microsoft started paying more attention [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[461,333],"class_list":["post-2222","post","type-post","status-publish","format-standard","hentry","category-code","tag-html","tag-internet-explorer"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2222"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2222\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}