Tweaking Various Body Classes for Cross-Browser Compatibility in Drupal
Have you ever noticed that some CSS implementation in the Mozilla Firefox browser displays differently than in today’s other leading browsers, including Internet Explorer, Google Chrome, Opera and Safari? If you have, then this blog is for you! Often times, only web developers notice these differences, but if you are a keen observer of how a website looks, you will definitely spot the differences. This article discusses ways to implement the cross-browser compatibility check in Drupal sites.
<?php
function [name_of_the_default_drupal_theme]_preprocess_page(&$vars) {
$vars['body_classes'] .= ' ';
$vars['body_classes'] .= browser_detect();
if(trim(strtolower($vars['title'])) == 'english'){
$vars['body_classes'] .= ' ';
$vars['body_classes'] .= 'english-page-ltr-style';
}
}
function browser_detect() {
$browsers = "mozilla msie gecko firefox ";
$browsers.= "konqueror safari netscape navigator ";
$browsers.= "opera mosaic lynx amaya omniweb chrome";
$browsers = split(" ", $browsers);
$nua = strToLower( $_SERVER['HTTP_USER_AGENT']);
$l = strlen($nua);
for ($i=0; $i<count($browsers); $i++){
$browser = $browsers[$i];
$n = stristr($nua, $browser);
if(strlen($n)>0){
$GLOBALS["ver"] = "";
$GLOBALS["nav"] = $browser;
$j=strpos($nua, $GLOBALS["nav"])+$n+strlen($GLOBALS["nav"])+1;
for (; $j<=$l; $j++){
$s = substr ($nua, $j, 1);
if(is_numeric($GLOBALS["ver"].$s) )
$GLOBALS["ver"] .= $s;
else
break;
}
}
}
$my_browser = ($GLOBALS["nav"] . " " . $GLOBALS["ver"]);
switch ($my_browser) {
case "msie 6.0":
$my_browser = "ie ie6 ie8-earlier";
break;
case "msie 7.0":
$my_browser = "ie ie7 ie8-earlier";
break;
case "msie 8.0":
$my_browser = "ie ie8 ie8-earlier";
break;
case "msie 9.0":
$my_browser = "ie ie9";
break;
}
return $my_browser;
}


Comments
Post new comment