[Pmwiki-users] IE

Patrick R. Michaud pmichaud
Mon Dec 20 21:51:26 CST 2004


On Mon, Dec 20, 2004 at 07:22:15PM -0500, Tom Holroyd wrote:
> What is the best way to emit custom CSS depending on the browser?

First, I'll note that lots of well-regarded sites (notably
alistapart.com) frown on the idea of changing the text emitted based
on the browser.  But I'm not one to stand on such principles, soo....

The first step is to be able to identify IE from other browsers.
Microsoft recommends checking HTTP_USER_AGENT for "MSIE" -- if it's
there then it's running IE (or is at leas somewhat claiming to be
IE).

Once you've identified the browser as IE, it's just a matter of
emitting the additional CSS it needs.  So, if you want embedded
styles:

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
  $HTMLStylesFmt['msie'] = '
    /* your IE-specific styles here */
  ';
}

If you want to load from an external stylesheet:

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
  $HTMLHeaderFmt['msie'] =
    "<link rel='stylesheet' href='\$SkinDirUrl/msie.css' type='text/css' />";
}

If you want to go the other way -- i.e., to include styles only if
the browser is not MSIE, then just change "!== false" above to 
be "=== false" instead.

Pm



More information about the pmwiki-users mailing list