views:

61

answers:

2

I want to load a specific - additional - style sheet when scripting is disabled in the browser.

Is there a nice / clean way to test for that or should I just use a script tag and a document.write() to add the style sheet?

+2  A: 

Why you wont use <NOSCRIPT> tag?

It can be used in HEAD section, because it is used in any place, where SCRIPT can be used as an alternative.

Thinker
Can you use <noscript> in the head of the document?
jeroen
Is noscript cross-browser or just IE?
Janie
Noscript is cross browser
Flubba
I don't think noscript is *technically* allowed within the head. It may work in some browsers, but that could change later on.
Sean Nyman
The spec allows noscript elements only where block elements are allowed (so not in the head) and only allows it to contain block elements (so not the link element you need to add a stylesheet).
David Dorward
You are wrong David, because NOSCRIPT is alternative to SCRIPT tag, so can be used any place, where SCRIPT could be used.
Thinker
XHTML 1.0 Strict and HTML 4.0 Transitional DTDs say that it is **not** technically allowed within head. The only elements *technically* allowed in head are: script, style, meta, link, and object.See: http://www.w3.org/TR/html4/sgml/loosedtd.html
coderjoe
@Thinker It would make sense for it to be designed that way, but it wasn't.
David Dorward
+3  A: 

I'd work the other way. Override the styles if scripting IS available. i.e. build on top of a page that works without JS rather than trying to test if JS isn't available.

I'd probably roll them into a single stylesheet and then throw a:

<script type="text/javascript"> 
  document.body.className += " js";
</script>

into the page.

David Dorward
Would that work in all browsers, multiple classes on one element?
jeroen
My example doesn't involve multiple classes on one element. It involves a single class on a single element. Internet Explorer 6 has trouble if you have a CSS selector that tries to match two classes on one element at the same time ( e.g. body.js.something ) but each can be used on its own without any trouble (e.g. body.js AND body.something)
David Dorward
Thanks, I think I will use something similar to your example.
jeroen