tags:

views:

262

answers:

3

I have a webpage that has a comment box that can be toggled by clicking a link (the opening and closing of the box is controlled using JavaScript, specifically JQuery). This box is hidden by default, so naturally, it's impossible to display without the use of JavaScript. I'm not concerned by this fact: the comment box is not a "necessary" feature and this is a small personal site, so I don't mind that a tiny percentage of visitors may not experience full functionality. However, I would like to display a warning if the user does not have JavaScript enabled.

I've considered the idea of doing this by presenting a small message (with the use of a simple HTML <p> tag) near the link that toggles the comment box, using the following bit of code:

<p class="alert" id="nojs-warning">You must have JavaScript enabled to leave a comment.</p>

Of course, I don't want to display this if JavaScript is enabled, so I have the following JQuery trigger set up to immediately hide the box when the page is loaded:

$(function() {
    $('#nojs-warning').hide();
});

Thus, if the user has JavaScript enabled, the event will fire and the warning will be hidden; if the user doesn't have JavaScript enabled, the event won't fire, and thus the warning will still be displayed.

For such a small, personal site, this seems like an elegant solution. Are there any pitfalls to this approach?

+8  A: 

Why not use the <noscript> tag? That's what it's intended for.

Franci Penov
Simple answer: for some reason, I completely forgot about that tag!
mipadi
Lol, it's happened to me as well... :-)
Franci Penov
A: 

The only obvious concern is that the function doesn't run even if javascript is enabled. Is there a particular reason you aren't using the tag built into HTML. It's likely doing the same thing but without the need for javascript. link text

Paulo
A: 

Better yet: why not just have the comment box on the site, and hide it with Javascript for those with Javscript? Then everyone can use it, right?