Solved

How to test for Compatibility View in IE8?

Posted on 2014-11-03
3
390 Views
Last Modified: 2014-11-03
Experts,

I need to alert users to the fact that Compatibility View is on when using IE8.

Is there a way to do this using PHP?

If so, I guess I would do the following:

1) Test to see if browser type equals IE
2) Check to see if Compatibility View is on
3) If Compatibility View is on, alert the user via javascript

I've found some articles on the web that speak to this idea but, none of the examples or proposed solution allow testing via PHP and/or java script.

Can this be done?

Cheers!
0
Comment
Question by:evibesmusic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40420621
from https://gist.github.com/jasongaylord/5733469

You can do it in javascript:

html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Testing IE Compatibility Mode</title>
    <script src="ieUserAgent.js" type="text/javascript"></script>
</head>
<body>
<div id="results">Results:</div>
<script type="text/javascript">
    var val = "IE" + ieUserAgent.version;
    if (ieUserAgent.compatibilityMode)
        val += " Compatibility Mode (IE" + ieUserAgent.renderVersion + " emulation)";
    $("#results").html("We have detected the following IE browser: " + val);
</script>
</body>
</html>

Open in new window


Javascript:
// Check to see if jQuery is loaded. If not, load it from the public jQuery CDN.
if (typeof jQuery == 'undefined') {
    // Load the latest jQuery library from jQuery
    document.write("\<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'>\<\/script>");
}
 
// Create new ieUserAgent object
var ieUserAgent = {
    init: function () {
        // Get the user agent string
        var ua = navigator.userAgent;
        this.compatibilityMode = false;
        
        // Detect whether or not the browser is IE
        var ieRegex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (ieRegex.exec(ua) == null)
            this.exception = "The user agent detected does not contai Internet Explorer.";
 
        // Get the current "emulated" version of IE
        this.renderVersion = parseFloat(RegExp.$1);
        this.version = this.renderVersion;
 
        // Check the browser version with the rest of the agent string to detect compatibility mode
        if (ua.indexOf("Trident/6.0") > -1) {
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
                this.version = 10;                  // IE 10
            }
        }
        else if (ua.indexOf("Trident/5.0") > -1) {      
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
                this.version = 9;                   // IE 9
            }
        }
        else if (ua.indexOf("Trident/4.0") > -1) {
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
                this.version = 8;                   // IE 8
            }
        }
        else if (ua.indexOf("MSIE 7.0") > -1)
            this.version = 7;                       // IE 7
        else
            this.version = 6;                       // IE 6
    }
};
 
// Initialize the ieUserAgent object
ieUserAgent.init();

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40420632
I don't know about finding compatibility mode in PHP, but you can examine the clients' browser information, expecting to find something like this:

$_SERVER["HTTP_USER_AGENT"] = Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko

The rv:11.0 means Version 11.  Any browser that is backlevel probably earns a notice that it's time to upgrade.
0
 

Author Closing Comment

by:evibesmusic
ID: 40420649
Perfect. Thank you very much.
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question