Solved

How to test for Compatibility View in IE8?

Posted on 2014-11-03
3
384 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 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