Long story short: Some quite nice interative SVG map works fine on every major web browser thanks to svgweb. Except IE, of course. Every IE (8, 9, 10) needs a particular workaround. IE9 would only work when I force it into compatibility mode. Unfortunately I can't find a way to use drupal_add_html_head with #tag' => meta and #prefix and #suffix to only take effect in IE9. drupal_add_html_head works fine, but #prefix and #suffix discard it. So that doesn't work:

$meta_ie_render_engine = array(
  '#type' => 'html_tag',
  '#tag' => 'meta',
  '#attributes' => array(
    'http-equiv' => 'X-UA-Compatible',
    'content' =>  'IE=7',
  '#weight' => '-99999',
  '#prefix' => '<!--[if IE 9]>',
  '#suffix' => '<![endif]-->',
drupal_add_html_head($meta_ie_render_engine, 'meta_ie_render_engine');

Is there another way to use drupal_add_html_head with tag => meta conditionally? Or another drupal-like alternative?

  • I would just hardcode the X-UA-Compatible meta tag into your html.tpl.php file in your theme folder. That's an acceptable way of doing it. – chrisjlee Nov 11 '13 at 15:53
  • Isn't there anything I can add to my already existing SVG module to keep everything in one place? That would make Features export/import and also future maintainance easier. – leymannx Nov 11 '13 at 15:58
  • I don't know what your svg module does or how it relates to this particular question. But just modify your theme template found in /sites/all/themes/<yourtheme>/html.tpl.php. That's typically what you do in Drupal. – chrisjlee Nov 11 '13 at 16:00

Had similar problem:

function detect_ie() {
    if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) {
        return true;
    else {
        return false;

above will detect if IE in general. You will need to change 'MSIE' accordingly (something like 'MSIE9' but not sure if thats correct).

Then what i did was

if(detect_ie()) {
  $element = array(
  '#tag' => 'meta',
  '#attributes' => array(
  'http-equiv' => 'X-UA-Compatible',
    'content' =>  'IE=EmulateIE7',
drupal_add_html_head($element, 'IE_cr_ap');
  • 2
    UA detection on the server side will mess this up when you enable caching. – mpdonadio Nov 11 '13 at 16:30
  • 1
    It's 'MSIE 9.0'. – leymannx Nov 11 '13 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.