Forum Moderators: open

Message Too Old, No Replies

CSS while javascript is disabled

indication of javascript disablity

         

kadnan

8:04 am on Sep 15, 2005 (gmt 0)

10+ Year Member


i have DIV tag with some ID,i have kept it Invibile by setting display:none,if JS is enabled

i want to make it enable within <noscript> tag,how can I do this?

thanks

=adnan

Hester

8:53 am on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this?

<noscript>
<style type="text/css">
#yourid {display:block;}
</style>
</noscript>

[edited by: Hester at 8:53 am (utc) on Sep. 15, 2005]

kaled

8:53 am on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use <noscript> in the <head> but it won't validate.

Alternatively, it was suggested in an earlier thread that you can use document.write() to place html comments around a <style> tag that must be excluded when javascript is enabled. Similarly, you may use document.write() to insert a <style> tag.

e.g.
document.writeln('<style>');
............
document.writeln('<\/style');

NOTE
If the code is embedded in an html document, / must be escaped when it follows <

Kaled.

Bernard Marx

10:32 am on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bernard Marx suggests:

Set your default styles for the script disabled, then include contextual rules for enabled browsers
(Mr Marx is very politically correct this week).

[blue]
#myDiv {width: 300px; height: 500px;}
.scriptEnabled #myDiv {display:none;} /* enhance for the enabled */
[/blue]

Now, the first thing you do in your script is:

[color=brown]document.getElementsByTagName('html')[0].className = "scriptEnabled";[/color]

..which can be done immediately, because the HTML element always exists
(perhaps

document.documentElement
would be more up-to-date)

This way, all the fiddling is kept external to the document (and neatly organised) - that's if you are using linked scripts & stylesheets, natch.

The page will validate too. Yet it could be argued that you are introducing an invalid attribute when the page loads ('class' on HTML), but at least it's just an attribute, and furthermore, Mr. Marx say's he couldn't give a tinker's cuss about that anyway.

Bernard Marx

10:39 am on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BTW all these techniques will become unnecessary when a decent number of browsers support the full stylesheets interface (IE & Moz have for a long time now).

With that we can fiddle with CSS properties "at source" within the CSS rules.