Re: Browser Sniff - CSS

by "Jason K. Chapman" <theguild(at)interserv.com>

 Date:  Mon, 06 Nov 2000 07:55:01 -0500
 To:  <hwg-techniques(at)hwg.org>
 In-Reply-To:  net
  todo: View Thread, Original
At 10:35 AM 11/6/00 +1030, Shannon Doyle wrote:
>Hi Guys and Gals,
>
>I am in need of a browser sniff to detect what browser the user is using and
>then according to what they are running set a specific Style Sheet.
>
>ie I have a style sheet for IE and one for Netscape. What is the easiest way
>to do such a sniff?
>
>Any help would be appreciated.
>
>- Shannon

Depending on how many differences there are between the two sheets, you 
could just use NS's deficiency to solve the problem.

Here's an example:

Say you want a different background image for IE and NS.  Set the 
background with a specific style, say style="IE".  In the main sheet, do 
not define class "IE," but set the background image property of the BODY to 
the Netscape image.

At this point, both browsers will show the same background image and ignore 
the undefined class.

Now, above the body tag, put an @import statement to import a short style 
sheet which includes a definition for BODY.IE.  IE will obey the @import, 
read in the more specific definition, and present the alternate background 
image.

As long as you want NS to see the defaults and IE to see class-enhanced 
versions, this will work.

As an example, see <http://www.JasonKChapman.com/cosler/>.  IE gets a 
background image called hensel_hall_bg.jpg, whereas NS 4 gets 
hensel_hall_bg_ns.jpg.

The main sheet contains:

@import url("http://www.jasonkchapman.com/cosler/cosler2.css");
BODY {
         background-image: url("images/hensel_hall_bg_ns.jpg");
}

The second sheet contains:

BODY.ie {
         background-image: url("images/hensel_hall_bg.jpg");
         background-position : center;
         background-repeat : no-repeat;
         background-color : White;
}

Jason K. Chapman
======================================================
THE HERETIC by Jason K. Chapman, is a fast-paced cyber thriller
published by <http://www.happyhacker.org>. Coming soon in softcover,
ISBN 1-929925-38-7. Get the latest news at
<http://www.jasonkchapman.com>
======================================================

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA