How to Disable IE8 Compatibility Button

I was recently working on an ASP.NET MVC3 website and had users reporting that the site was crashing when they clicked a certain link. When I attempted to replicate the problem using the same web browser as the user, Internet Explorer 8, it seemed to work for me. After some back and forth, I discovered the problem was that the user had Compatibility Mode enabled for the website.

I then was able to recreate the error in IE by clicking the compatibility mode button (next to the refresh button).

The offending link on the page basically looked like this:

<a class="userid" href="#4">Some Text</a>

And the jQuery that was fired when clicking the link looked like this:

$('.userid').click(function (e) {

e.preventDefault();
var userId = $(this).attr('href'); // Get the href value
var userId = userId.replace('#',''); // Strip out the pound sign
window.location = '/ControllerName/ActionName?userId=' + userId;
});

So it should have been redirecting to this link:

/ControllerName/ActionName?id=4

But instead, IE compatibility mode had prepended the link with the full URL:

/ControllerName/ActionName?id=http://WebsiteName.com/CurrentControllerName/CurrentActionName4

Note: I had to use Fiddler to see exactly what URL IE8 was redirecting to.

The quick fix was to include a meta tag on that page:

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

By including the above meta tag, you are basically telling Internet Explorer that the website is compatible with IE8 which makes IE8 remove the Compatibility Button. If you go to google.com in IE8, you will also see that IE8 does not display a compatibility button.

*** Updated on 02/07/2012 ***

I am now using a newer and improved meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />

This will set the order of compatibility trying IE9 first, then IE8, etc.

Thanks to Twig for this tip. You can find his original post on this over at: http://twigstechtips.blogspot.com/2010/03/css-ie8-meta-tag-to-disable.html