user1173169
user1173169

Reputation:

How to turn on IE9 Compatibility View programmatically in Javascript

I need to turn on IE compatibility programmatically.

I know this works in C# :

Page.Header.Controls.AddAt(0, new HtmlMeta { HttpEquiv = "X-UA-Compatible", Content = "IE=EmulateIE7" });

My problem is all my windows are displayed in a JS function: for instance:

function openRadWin(idAgir) {
    radopen("DemandesEnAttente_Estimate.aspx?id=" + idAgir, "RadWindow1");

}

So my question is : is there any ways to do the same thing in JS?

Thanks in advance

Upvotes: 1

Views: 21368

Answers (3)

VinayC
VinayC

Reputation: 49185

AFAIK, this is not possible. You can detect the compatibility mode from JS but setting it is not possible to my knowledge.

As for as your problem goes, typically you can use few solutions:

  1. If you are using Master pages in your site, add the meta header (<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">) in the master page.
  2. Similar to #1, if you are using a common base page class (a good and recommended practice) then you can infuse the meta header from the common base page to all your pages.
  3. Lastly, you can use IIS configuration to add the http header to all your response.

For example, for IIS7/IIS7.5, you can use web.config

<system.webServer>
  <httpProtocol>
     <customHeaders>
       <remove name="X-UA-Compatible" />
       <add name="X-UA-Compatible" value="IE=EmulateIE7" />
     </customHeaders>
  </httpProtocol>
</system.webServer>

I would suggest #1 or #2 - in case you don't have master page or base page class then perhaps its a good time to introduce the both.

Upvotes: 6

Mike Chamberlain
Mike Chamberlain

Reputation: 42440

You could try adding this HTML tag to the top of any page that requires compatibility:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

That way you shouldn't need a JavaScript solution. Of course, if you have the ability to change the HTML, then the best solution would be to fix the page so it doesn't require backwards compatibility.

I believe that the only way to influence headers from the client side is when you request a page using an XmlHttpRequest. It doesn't make sense to me to talk about modifying headers after the page has loaded, which is in effect what you are asking.

Upvotes: 1

Joel Lundberg
Joel Lundberg

Reputation: 916

What your C# example does, is add the following meta tag to the html page:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">

If you do this manually on the page that runs the JS code, it should work.

Upvotes: 1

Related Questions