Solved

How to test for Compatibility View in IE8?

Posted on 2014-11-03
3
367 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
3 Comments
 
LVL 39

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 108

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

759 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now