Forum Moderators: not2easy

Message Too Old, No Replies

How do I use different style sheets with/without javascript?

         

kaled

9:53 am on Oct 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can use <NOSCRIPT> tags in the <BODY>.
I can use <STYLE> tags in the <HEAD>.

So there is no obvious way to wrap a <STYLE> tag within a <NOSCRIPT> tag.

A little research tells me that <NOSCRIPT> is defined in terms of rendering, hence the limitation of its use (within the <BODY> only) but this is just stupid.

Any suggestions?

Kaled.

Hester

3:16 pm on Oct 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use a stylesheet that is seen when JavaScript is off (via the usual <link> tag) then use JavaScript to change the reference so it points to a different stylesheet. Hence when JS is off, the change doesn't happen.

There's a page showing how to change styles with JavaScript, but it's a messy business not likely to work in all browsers!

[quirksmode.org...]

According to this list [quirksmode.org] of DOM commands, for CSS manipulation it gives the following results:

IE5/6 Windows - Yes
Explorer 5.2 Mac - Read Only (so you can't change the stylesheet - sigh)
Mozilla 1.6 - Yes
Safari 1.2 - Read Only
Opera 7.50 - No

Anyone know of a cross-browser method?

kaled

4:44 pm on Oct 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm experimenting with a dirty solution - I'm using the javascript document.write method to create a the style changes I need to work with my javascript-enabled layout.

Since there are only a few differences, between the two stylesheets I require for js and non-js this should be ok.

Whoever decided that the <NOSCRIPT> tag could not be placed within the <HEAD> should be put up against a wall and shot. So far as I can tell, IE, Opera and Mozilla all accept <NOSCRIPT> within the <HEAD> but I'm trying to move towards standards rather than away from them.

Kaled.

ricfink

5:04 am on Oct 9, 2004 (gmt 0)

10+ Year Member



Probably the most well-known style switching code was in an article (published in 2002) in a fairly well-known online-web publication.
the author's name is Paul Sowden. Should come up in a search under style sheet switching sowden or something close.

Wide support among all the major browsers.