You must first sign up to be able to contribute.

Version 5 (modified by newacct, 8 years ago)

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')

you have to install the browscap.ini

if you can not install, use this function:

        function _get_browser()
	  $browser = array ( //reversed array
	   "MSIE",            // parent
	   "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 )

  // to place your new stylesheet @ the bottom of the stack