How to turn on IE9 Compatibility View programmatically in Javascript

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.

posted @ 2014-03-27 20:40  happyu0223  阅读(201)  评论(0编辑  收藏  举报