[WEB4LIB] RE: Browser sniffing via javascript (was Draft home page not usable on my IE 6)

Diana Calder dcalder at essex.county.library.on.ca
Wed Jun 20 15:05:51 EDT 2001


Wednesday, June 20, 2001, 2:28:57 PM, Raymond Wood wrote:

RW> Lately I have seen a lot of 'browser sniffing' being done via javascript
RW> on web pages.  It works like this:
RW> 1. javascript code is used to determine whether (for sake of 
RW> argument) IE or Nav is being used.
RW> 2. separate stylesheets are employed (i.e. 1 for Nav, 1 for IE), and 
RW> the appropriate stylesheet is invoked depending on the result of the 
RW> browser sniff.

RW> I find I am uncomfortable with this method in principle, for what if the 
RW> user has javascript turned off?  Is there a better way to use 2 
RW> stylesheets, each customized for a different browser, without having 
RW> to rely on javascript?  Or, is it simply better to use one stylesheet for 
RW> all browsers (I have noticed that the main difference between the 2 
RW> stylesheets seems to be this - font sizes are expressed in 'pts' for 
RW> Nav, and in '%' for IE).

RW> I would be most interested in whatever best practices folks on this 
RW> list might recommend in this case.

Frankly, I'm uncomfortable with ANY form of browser sniffing -
ninety-nine times out of a hundred, there is NO need for it and almost
as frequently an either/or situation is set up that basically only
deals with IE and NS. A good example is homestead.com - any sites
located there test for browser type and redirect to a browser-specific
page (and on every site I've looked at, there has been NO coding that
should REQUIRE a browser-specific page). The problem - they only
provide alternatives for NS & IE - so if you visit the site with a
browser that reports itself as anything other than those, you get NO
page!! Visiting a Homestead-hosted site means that if you're using
Opera, you have to change its settings so that it reports itself as
either NS or IE. I'm guessing that if a visitor were using WebTV,
etc., the same problem would exist (blank or nearly-blank page
displayed) except that other browsers would not have Opera's option of
lying about their identity.  Possibly this only applies to sites that use the
online site builder, but every site I've visited at Homestead has had
this problem, so either they're ALL using the online site builder or
Homestead is automatically adding code to uploaded pages.  I've
e-mailed Homestead's support staff repeatedly about this, but have
been unsuccessful in getting them to understand the problem (I just
kept getting "canned" responses about the requirements for using site
builder).

Regardless, there is no need to specify different stylesheets for
different browsers (at least as long as the browser in question
supports CSS to a reasonable degree), particularly for font size
(using either 'pts' or '%' is not recommended, xx-small through
xx-large should be used for absolute sizes and larger and smaller
should be used for relative sizes.  See
http://www.htmlhelp.com/reference/css/font/ for a more thorough
explanation.


"Style sheet designers should take care to always ensure that their
Web pages are in no way dependent on the style sheet." (from
http://www.htmlhelp.com/reference/css/dependence.html )

-- 
Diana Calder
Automation Technician
Essex County Library                mailto:dcalder at essex.county.library.on.ca





More information about the Web4lib mailing list