4

I have thousands of pages on a CMS driven site that render poorly from within the company network because IE treats them as intranet pages, and the default setting for IE is to render intranet pages in compatibility mode.

I want to insert the IE Edge meta tag after the title tag to force the browser into its latest version, but I can't edit every page for this. To avoid editing individual pages or having to regenerate pages in the CMS, I think I should be able to update an include that is common to all pages with a server side script that does it. Is that possible? I think it needs to be server side because adding the meta tag at onload doesn't force the browser mode, but maybe I'm wrong.

So I want this:

<head>
...some stuff...
<title>My Title</title>
...some other stuff...
<!--#include virtual="/myinclude.asp"-->
</head>

To become this:

<head>
...some stuff...
<title>My Title</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
...some other stuff...
...rendered include...
</head>

Is there a way to do this? Or some other workaround I'm not seeing?

AnonJr
  • 2,759
  • 1
  • 26
  • 39
Kfunk
  • 71
  • 1
  • 8

2 Answers2

3

It turns out you can add things to the header with this:

<%  Response.AddHeader "CustomHeader","CustomValue" %>

It also appears that it doesn't matter where I put it on the page, so I can stick it in the common include, and all pages will get the custom header. In this case:

<% Response.AddHeader "X-UA-Compatible","IE=Edge,chrome=1" %>

Wish I had known about this way sooner! Here's the spec:

http://msdn.microsoft.com/en-us/library/ms524327(v=vs.90).aspx

Kfunk
  • 71
  • 1
  • 8
  • For future readers, the reason this works is IIS5+ buffers content by default and "fixes" the order of information sent. Having worked with ... older ... version of IIS I was still thinking of the days that the order of what you sent mattered. If you turn buffering off, the order of information will matter again. – AnonJr Oct 03 '13 at 21:23
  • For the lurkers: The Chrome tag is obsolete/discontinued Q1 2014 http://blog.chromium.org/2013/06/retiring-chrome-frame.html. – Joe Johnston Jun 27 '16 at 15:10
2

You can set IIS to send the header for all pages served. An MSDN article describes the steps as:

Configuring the EmulateIE7 HTTP Header in IIS7 (via the user interface)

  1. Open Internet Information Services (IIS) Manager
  2. Select the Server from the connections pane
  3. Right-click on “HTTP Response Headers” from the center task pane, and choose “Open Feature”
  4. Select “Add” from the Actions Pane
  5. Add a custom header with the Name “X-UA-Compatible” and the Value “IE=Edge”

They also have the steps for making the changes via command line.

There's an article on the IIS Blog that gives you a list of possible values and what they will do.

Emulate IE8 mode  -->   IE=EmulateIE8
Emulate IE7 mode  -->   IE=EmulateIE7
IE5 mode          -->   IE=5
IE7 mode          -->   IE=7.5
IE8 mode          -->   IE=8
Edge mode         -->   IE=Edge
AnonJr
  • 2,759
  • 1
  • 26
  • 39
  • Okay, this makes sense, although I don't have access to IIS, and will have to send a request to see if it can be done. There are also intranet pages being served and older pages which I don't necessarily want to change. No other way to force it from an include, which I could actually do myself? – Kfunk Oct 02 '13 at 18:49
  • @Kfunk Short of setting the header on IIS, there's no easy way to change all pages unless there was already a common include in the head of all the pages (which it didn't sound like from the original question). There may be some happy medium with a comparability mode that allows the CMS to run right and not adversely effect the other sections of the server - that's part of why I included the larger list of options. – AnonJr Oct 02 '13 at 18:58
  • There _is_ an include in the head in common with all the pages I want to affect, like in my brief example. My understanding is that the UA meta tag has to come directly after the title, however, to work correctly, and that is the problem. Like in this answer: http://stackoverflow.com/a/9624500/2839314. Is there not a server side script that would do the same, like this PHP answer? http://stackoverflow.com/a/10077921/2839314 – Kfunk Oct 02 '13 at 19:19
  • @Kfunk there is a way to send a custom header, but if I remember right it would have to be sent before you sent *any* HTML to the browser. – AnonJr Oct 02 '13 at 19:52
  • Thanks for your ideas - the info you gave me was helpful. If I wasn't a noob, I'd give you an up tick. Ultimately, this led me to what I think is the right solution for my situation (see my answer), using `Response.AddHeader`. – Kfunk Oct 03 '13 at 18:06
  • @Kfunk Glad I could help. I could have sworn you needed to do the `Response.AddHeader` before you did the rest of the HTML, but as long as it works. :) – AnonJr Oct 03 '13 at 21:17