Natural selection browser switch

Mat Colton mat.colton at web-xs.de
Thu Mar 13 14:23:27 UTC 2003


BTW, before I forget it, I posted on 2003.03.07:
***************
consider changing <body> to <body id="wwwkdeorg"> so anyone can write a 
personal style sheet for each KDE site. Of course kate.kde.org would be <body 
id="katekdeorg"> etc..
***************
This gives the user true freedom to style to his personal taste without write 
access to the server and it's so easy to implement. :P

Am Donnerstag, 13. März 2003 02:56 schrieb Olaf Jan Schmidt:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> [Mat Colton]
>
> > Please use the
> > "natural selection" via CSS and JS DOM. First of all it is not a hack
> > compared to a http browser switch and second it works. :)
>
> This does not work if you include several style sheets to let the user
> choose between them. Any other ideas?

Hmm, maybe I'm not getting the point.

> The test I implemented to check for the correct browser is pretty
> standard, I searched the web for possible problems but did not find any
> browsers that would match the Netscape 4.x useragent without adding
> "compatible".
> But as I said, if you know a way to hide multiple style sheets from
> Netscape (not possible with @import), then please let me know.

@media doesn't work for NS4 or IE4 so voila, natural selection. The backdraw 
is IE 5 for MacOS can't handle it either, so the only way I found how to do 
it is with additional JS:

/*
IE 5 on Mac can't handle @media, so we hand over the CSS this way.
*/
if ((navigator.appName == "Microsoft Internet Explorer") &&
    (navigator.appVersion.indexOf("MSIE 5") != "-1") &&
    (navigator.appVersion.indexOf("Mac") != "-1"))
{
  document.write('<link rel="stylesheet" type="text/css" href="css/screen.css" 
media="screen" />');
  document.write('<link rel="stylesheet" type="text/css" href="css/print.css" 
media="print" />');
}

The overhead is having to offer 2 versions of each CSS. I have found the 
overhead is acceptable if the site is well planned and doesn't change the CSS 
stuff too often. Now one could say this is bad because it requires JS to be 
on, but in reality everybody using IE has JS on.
-- 
Bye,
Mat





More information about the kde-www mailing list