How to include a stylesheets depending on the user's browser
use this code in layout.php (example is for detecting IE)
// detect ie
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$browser=get_browser(null, true);
if ($browser['browser']=='IE')
sfContext::getInstance()->getResponse()->addStylesheet("ie.css");
}
you have to install the browscap.ini
if you can not install, use this function:
function _get_browser()
{
$browser = array ( //reversed array
"OPERA",
"MSIE", // parent
"NETSCAPE",
"FIREFOX",
"SAFARI",
"KONQUEROR",
"MOZILLA" // parent
);
$info['browser'] = "OTHER";
foreach ($browser as $parent)
{
if ( ($s = stripos($_SERVER['HTTP_USER_AGENT'], $parent)) !== FALSE )
{
$f = $s + strlen($parent);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
$version = preg_replace('/[^0-9,.]/','',$version);
$info['browser'] = $parent;
$info['version'] = $version;
break; // first match wins
}
}
return $info;
}
You can also place your new stylesheet at the beginning or end of the stack. Simply use the 'position' argument of the addStylesheet() method.
// to place your new stylesheet @ the top of the stack ( ie. YUI reset )
sfContext::getInstance()->getResponse()->addStylesheet("ie.css","first");
// to place your new stylesheet @ the bottom of the stack
sfContext::getInstance()->getResponse()->addStylesheet("ie.css","last");