Click here to Skip to main content
15,071,581 members
Articles / Web Development / ASP.NET
Article
Posted 19 Sep 2014

Stats

12.6K views
3 bookmarked

How your web site can determine if the user is running their IE browser in compatibility mode.

Rate me:
Please Sign up or sign in to vote.
1.86/5 (5 votes)
19 Sep 2014CPOL2 min read
This article show a quick way to determine if a user's IE browser is in compatibility mode.

Compatibility.png

Introduction

As more websites are using HTML5 and 3rd party controls that use HTML5, we do not want a user’s browser using compatibility mode.  This article suggests one way you can determine if a browser is in compatibility mode.

Background

The company I work for used to require IE users to put their browser in compatibility mode for our web site to render properly.  Then we moved to a newer version of .net and HTML5.  Now we want our users to no longer use compatibility mode.

The Problem

When users log into our website we want to provide a message that will let them know they have compatibility mode turned on in their IE browser.  The problem is: What is the easiest way to figure out if they have compatibility mode turned on?

The Solution

I spent a bit of time trying to find the best way to figure out if a browser is in compatibility mode.  When you google how to find a browser's compatibility mode you will find all sorts of solutions.  There is a JavaScript solution.  There is a solution where you look at the Request.UserAgent in your .net code.  As I looked through these options, they seemed more complicated and could possibly break as new versions of IE come out.  As I looked for a common thread I found that in any browser, as of this writing we are at IE11, when put into compatibility mode looks like IE7.  So here is my solution:

VB.NET
'VB.net 
'check for compatibility mode
If Request.Browser IsNot Nothing AndAlso _
   Request.Browser.Browser = "IE" AndAlso _
   Request.Browser.Version = "7.0" Then
   'show error or do action
End If

 

C#
//C#
//check for compatibility mode
if (Request.Browser != null && Request.Browser.Browser == "IE" && 
    Request.Browser.Version == "7.0") {
    //show error or do action
}

Of course the downside to this solution is that if someone is actually using IE7 they will see a message that tells them to turn off compatibility mode.  This is a risk I am willing to take.

Conclusion

This is a simple solution to determine in your website if a user is using compatibility mode.  If you need something more complicated there are more solutions out there.  I found this simple solution to work well for me.

History

First release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kubben
Software Developer (Senior)
United States United States
I started my programmer career over 21 years ago doing COBOL and SAS on a MVS mainframe. It didn't take long for me to move into windows programming. I started my windows programming in Delphi (Pascal) with a Microsoft SQL server back end. I started working with vb.net when the beta 2 came out in 2001. After spending most of my programming life as a windows programmer I started to check out asp.net in 2004. I achieved my MCSD.net in April 2005. I have done a lot of MS SQL database stuff. I have a lot of experience with Window Service and Web services as well. I spent three years as a consultant programing in C#. I really enjoyed it and found the switch between vb.net and C# to be mostly syntax. In my current position I am programming in C# working on WPF and MSSql database stuff. Lately I have been using VS2015.

On a personal note I am a born again Christian, if anyone has any questions about what it means to have a right relationship with God or if you have questions about who Jesus Christ is, send me an e-mail. ben.kubicek[at]netzero[dot]com You need to replace the [at] with @ and [dot] with . for the email to work. My relationship with God gives purpose and meaning to my life.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Jeremy Falcon19-Sep-14 10:46
professionalJeremy Falcon19-Sep-14 10:46 
GeneralRe: My vote of 1 Pin
kubben19-Sep-14 11:31
Memberkubben19-Sep-14 11:31 
GeneralRe: My vote of 1 Pin
Jeremy Falcon19-Sep-14 11:55
professionalJeremy Falcon19-Sep-14 11:55 
GeneralRe: My vote of 1 Pin
kubben19-Sep-14 12:23
Memberkubben19-Sep-14 12:23 
GeneralRe: My vote of 1 Pin
Jeremy Falcon19-Sep-14 12:38
professionalJeremy Falcon19-Sep-14 12:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.