Skip to content

Instantly share code, notes, and snippets.

@swirtSJW
Last active August 29, 2015 14:06
Show Gist options
  • Save swirtSJW/49c5bf994023dd31e64b to your computer and use it in GitHub Desktop.
Save swirtSJW/49c5bf994023dd31e64b to your computer and use it in GitHub Desktop.
This is a variation of what I use to force ie to edge on a drupal site. I use it in Codit module. https://www.drupal.org/project/codit
/**
* Implements hook_init().
*/
function mymodule_init() {
// This is called on every page request (cached and non-cached).
mymodule_set_ie_to_edge();
}
/**
* Set the header to force IE to edge mode (the highest level of IE installed).
*/
function mymodule_set_ie_to_edge() {
// Force ie to not use compatibility mode.
if (!empty($_GET) && !empty($_GET['debug']) && ($_GET['debug'] == 'ie')) {
// There is a debug so do not force to use edge, do nothing.
}
else {
// There is no debugging going on, so force ie to use edge.
header('X-UA-Compatible: IE=edge');
// Send X-UA-Compatible HTTP header to force IE to use the most recent
// rendering engine or use Chrome's frame rendering engine if available.
// It is not possible to use drupal_add_http_header() as Drupal 7 does not
// store HTTP headers in the page cache.
$element = array(
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge',
),
);
// This element has no effect on forcing edge, but is a visual indicator in the
// html head of what is happening.
drupal_add_html_head($element, 'x_ua_compatible');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment