RE: controlling CSS load via JavaScript?

From: Aleksandr Vladimirskiy <aleksandrv_at_berkeley.edu>
Date: Thu Jul 06 2006 - 12:55:01 PDT

Hi Kalle,

According to Microsoft to separate code based on IE versions you should use
conditional comments. They're recognized by versions of IE from 5 and up.

<!--[if lte ie 5.5000]>
<style type="text/css">
/* some style */
</style>
<![endif]-->

Example 1.
The above code prevents any browser newer than IE 5 from seeing the CSS.
"lte" - less than or equal to.

<!--[if gt ie 5.5000]>
<style type="text/css">
/* some style */
</style>
<![endif]-->

Example 2.
Or as an alternative, the above code hides the CSS from IE 5. "gt" - greater
than.

The caveat is that browsers other than IE will completely ignore CSS inside
the conditional comments and you'd have to organize the CSS accordingly. For
example first include all CSS, than inside the comments that will only get
displayed on IE 5(Example 1) include corrections that will override the
preceding CSS for that particular browser.

I wouldn't use JavaScript to make decisions about CSS since JavaScript can
be turned off by the client.

Aleksandr Vladimirskiy
Web Developer
College of Engineering, Dean's Office
UC Berkeley
306A McLaughlin Hall
510-642-6385
________________________________________
From: owner-webnet-list@lists.berkeley.edu
[mailto:owner-webnet-list@lists.berkeley.edu] On Behalf Of Kalle Nemvalts
Sent: Thursday, July 06, 2006 11:55 AM
To: webnet-list@berkeley.edu
Subject: [Webnet] controlling CSS load via JavaScript?

I have a CSS stylesheet that works with current generation browsers but is
unsightly (though still more or less functional) with Windows IE 5 and
earlier.

I'm thinking about using a JavaScript function to load the stylesheet
conditionally, based on browser detection. It would load the CSS for all
browsers except a short list of older browsers. (Exception detection might
later be expanded to include PDAs, etc.)

Without the CSS, the page would display linearly as plain HTML.

However, any browser with JavaScript disabled would also not load the CSS.

What's the current thinking on requiring JavaScript?

Any suggestions for alternative ways to turn off CSS for older browsers?

Thanks,

Kalle

Kalle Nemvalts
IST Public Information
2195 Hearst Ave 250-46 MC 3812
kalle@berkeley.edu
(510) 642-7582

-----------------------------------------------------------------------
The following was automatically added to this message by the list server:

Webnet information is available at http://webnet.berkeley.edu. Email sent to this list is archived at http://ls.berkeley.edu/mail/webnet/ . This archive is open to the general public and browsable by search engine spiders, email-address harvesting robots, your bosses, etc.
Received on Thu Jul 6 12:57:22 2006

This archive was generated by hypermail 2.1.8 : Thu Jul 06 2006 - 12:57:22 PDT