views:

9106

answers:

8

Is there a way to force ie8 into ie7 compatibility mode using .net or javascript?

+27  A: 

If you add this to your meta tags:

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

IE8 will render the page like IE7.

Serhat Özgel
You're right - but try to add it immediately after the opening <head> tag. I had problems when it was further down the page.
John McCollum
What if I don't to add this line to every aspx page on my site. Can I do it with IIS?
Bryan
@Bryan: No. This is why we use master pages.
Chris Lively
See DDaviesBrackett's answer below for doing it at the site level
Chris Lively
+3  A: 

I might have found it now. http://blog.lroot.com/articles/the-ie7-compatibility-tag-force-ie8-to-use-the-ie7-rendering-mode/

The site says adding this meta tag:

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

or adding this to .htaccess

Header set X-UA-Compatible IE=EmulateIE7
Bryan
+3  A: 

its even simpler than that. Using HTML you can just add this metatag to your page (first thing on the page):

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

If you wanted to do it using.net, you just have to send your http request with that meta information in the header. This would require a page refresh to work though.

Also, you can look at a similar question here: http://stackoverflow.com/questions/934178/compatibility-mode-in-ie8-using-vbscript

Matt Dunnam
+6  A: 

There is an HTTP header you can set that will force IE8 to use IE7-compatibility mode.

DDaviesBrackett
A: 

A note to this:

IE 8.0s emulation only promises to display the page the same. There are subtle differences that might cause functionality to break. I recently had a problem with just that. Where IE 7.0 uses a javascript wrapper-function called "anonymous()" in IE 8.0 the wrapper was named differently.

So do not expect things like JavaScript to "just work", because you turn on emulation.

jAST
Writing code that depends on the "name" of an anonymous function is not a reliable dependency to take, regardless of browser version.
EricLaw -MSFT-
+2  A: 

one more if you want to switch IE 8 page render in IE 8 standard mode

<meta http-equiv="X-UA-Compatible" content="IE=100" /> <!-- IE8 mode -->
Gaurav M
A: 

Hello, I have a reverse problem. This site is http://www.mypole-ishhorseshoes.com In IE7 the links are broken and off center. In IE8 firefox and chrome they are all consitent and work correctly? Can any one help me out. continuation of previous I am the web designer for this site and I cannot find a code to correct this thanks email [email protected]

ian
+1  A: 

You can do it in the web.config

    <httpProtocol>
        <customHeaders>
            <add name="X-UA-Compatible" value="IE=7"/>
        </customHeaders>
    </httpProtocol>

I have better results with this over the above solutions. Not sure why this wasn't given as a solution. :)