Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Issue #623 : Detect IE Compatibility Mode #2098

Closed
wants to merge 2 commits into from

2 participants

@AndrewPodner

Uses the reported browser version number and trident engine version number to determine if Internet Explorer is running in compatibility mode. If compatibility mode is detected, the browser will be appended to read "Internet Explorer (Compatibility Mode)" and the version will be adjusted to the actual version of IE that is being used based on the trident engine version

Additionally added a method to return a boolean value whether or not compatibility mode has been detected.

@AndrewPodner

Should I go ahead and close this out, or look for a different method to accomplish it?

@narfbg
Owner

I don't think that it belongs in CI.

@AndrewPodner

Ok, no problem. I only worked on it because #623 was still open and had been tagged as a new feature. Is there a way I tell which Issues are open and need somebody to work on them and which ones do not need to be worked on.

@narfbg
Owner

Closed #623. In general - any open issue needs work on it, but there are cases like this where it's a feature request that is yet to be decided on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 25, 2012
  1. @AndrewPodner
  2. @AndrewPodner

    issue #623 : Add support for detection of Internet Explorer running i…

    AndrewPodner authored
    …n compatibility mode. (fix missing new line in changelog)
This page is out of date. Refresh to see the latest.
View
7 application/config/user_agents.php
@@ -104,6 +104,13 @@
'IBrowse' => 'IBrowse'
);
+// Internet Explorer Trident engines used to determine IE7 compatibility mode
+$msie_compatibility_modes = array(
+ '8.0' => 'Trident/4',
+ '9.0' => 'Trident/5',
+ '10.0' => 'Trident/6'
+);
+
$mobiles = array(
// legacy array, old values commented out
'mobileexplorer' => 'Mobile Explorer',
View
60 system/libraries/User_agent.php
@@ -54,6 +54,13 @@ class CI_User_agent {
public $is_browser = FALSE;
/**
+ * Flag for if the user agent is MSIE in compatibility mode
+ *
+ * @var bool
+ */
+ public $is_compatibility_mode = FALSE;
+
+ /**
* Flag for if the user-agent is a robot
*
* @var bool
@@ -96,6 +103,13 @@ class CI_User_agent {
public $browsers = array();
/**
+ * List of MSIE trident engines to determine compatibility mode
+ *
+ * @var array
+ */
+ public $msie_compatibility_modes = array();
+
+ /**
* List of mobile browsers to compare against current user agent
*
* @var array
@@ -204,6 +218,13 @@ protected function _load_agent_file()
$return = TRUE;
}
+ if (isset($msie_compatibility_modes))
+ {
+ $this->msie_compatibility_modes = $msie_compatibility_modes;
+ unset($msie_compatibility_modes);
+ $return = TRUE;
+ }
+
if (isset($mobiles))
{
$this->mobiles = $mobiles;
@@ -285,6 +306,7 @@ protected function _set_browser()
$this->version = $match[1];
$this->browser = $val;
$this->_set_mobile();
+ $this->_set_msie_compatibility();
return TRUE;
}
}
@@ -345,6 +367,32 @@ protected function _set_mobile()
}
// --------------------------------------------------------------------
+ /**
+ * Detect MSIE Compatibility Mode (IE8, IE9, IE10)
+ *
+ * @return void
+ */
+ protected function _set_msie_compatibility()
+ {
+ // Check for any possible IE7 compatibility mode
+ if (strstr($this->agent, 'MSIE 7'))
+ {
+ // Iterate Trident engines, and look for a match
+ foreach ($this->msie_compatibility_modes as $version => $engine)
+ {
+ // If a match is found change to the real version and append
+ // browser name to show it is running in compatibility mode
+ if (strstr($this->agent, $engine))
+ {
+ $this->is_compatibility_mode = TRUE;
+ $this->browser .= ' (Compatibility Mode)';
+ $this->version = $version;
+ }
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
/**
* Set the accepted languages
@@ -516,6 +564,18 @@ public function browser()
// --------------------------------------------------------------------
/**
+ * Get whether browser is MSIE in compatibility mode
+ *
+ * @return bool
+ */
+ public function compatibility_mode()
+ {
+ return $this->is_compatibility_mode;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get the Browser Version
*
* @return string
View
4 user_guide_src/source/changelog.rst
@@ -267,7 +267,9 @@ Release Date: Not Released
- :doc:`Migration Library <libraries/migration>` changes include:
- Added support for timestamp-based migrations (enabled by default).
- Added ``$config['migration_type']`` to allow switching between *sequential* and *timestamp* migrations.
- - :doc:`User Agent Library <libraries/user_agent>` will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions).
+ - :doc:`User Agent Library <libraries/user_agent>` changes include:
+ - Will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions).
+ - Will detect Internet Explorer 8,9,10 running in IE7 compatibility mode
- Core
View
8 user_guide_src/source/libraries/user_agent.rst
@@ -127,6 +127,14 @@ $this->agent->browser()
Returns a string containing the name of the web browser viewing your
site.
+$this->agent->compatibility_mode()
+==================================
+
+Returns a boolean identifying whether or not Internet Explorer running
+in compatibility mode was detected in the user agent string. This is
+based on comparing the reported browser version to the Trident engine
+version in the user agent string.
+
$this->agent->version()
=======================
Something went wrong with that request. Please try again.