views:

77

answers:

2

What's the best way to implement a "you must have JS enabled" message? My site simply won't work without JS at the moment.

Should I use the <noscript> tag? Should I hide the entire page's content, put a message about needing JS enabled, and then hide the message and show the content with JS? -- This might cause the message to be temporarily visible.

Is there a site I can direct my users to that describes how to enable JS in different browsers? Maybe a blurb about that stupid noscript FF addon too?

+4  A: 

Use the noscript tag, that will only be visible when scripting is unavailable (i.e. disabled).

Additionally, you can initially hide some features using css and enable them with script.

Enabling scripting is specific for each browser, so you might have to link to several pages to cover all browsers used in your target group. This Microsoft page covers some of the most popular.

Guffa
I know it's specific..that's why I was hoping there was a site that lists how to do it in all the different browsers. Otherwise I could slap up one little link and be done with it :p `<noscript>` is compatible across all browsers? Like IE6+?
Mark
@Mark: The `noscript` tag works in all browsers ever made. If you happen to have a browser so ancient that it doesn't know about the `noscript` tag (e.g. IE 2), it will ignore the tag and show it's contents, so it will still work.
Guffa
Although, I'd argue that if you're still supporting IE2, your problems are much larger than how to implement `<noscript>`.
Mark Trapp
+1  A: 

you could also hide the wrapper in the content like

<body>
    <div class="js-on">
       ...content here
    </div>
    <div class="js-off">
      warning: you must have javascript enabled
    </div>
</body>

.js-on{display:none;}
.js-off{display:block;}

and remove/toggle both classes with javascript. ;)

but as a fallfack for browsers that do not support css:

      <noscript>

-tag is the best solution

Caspar Kleijne
well, that's what i was trying to describe in my q, but that'll cause the warning to appear for a second even for users that *do* have JS enabled.
Mark
the js-on script should indeed be placed in the head to avoid this. not below the content or in jQuery onload
Caspar Kleijne
@Caspar: how? The div *does* need to be loaded for the script to work.
Mark
@mark: the trick is to add the clasname to the dom in the head : read this: http://greatwebguy.com/programming/dom/enable-javascript-specific-css-with-one-line-of-jquery/ and this http://greatwebguy.com/programming/css/writing-javascript-specific-css/
Caspar Kleijne
ah... you apply the style to the document node instead, which is immediately loaded. clever. when combined with `<noscript>` this should work well. thanks.
Mark