Shane O'Sullivan's technical blog… really ties the room together

Displaying a ‘JavaScript is Required’ message

Posted by Shane O'Sullivan on December 21, 2008

A quick tip on a very simple pattern that can be used to tell a user who has JavaScript disabled that they have to turn it on.  Place the message you want to show between two script blocks that simply write a div around the message, setting it’s display to ‘none’.  If JavaScript is enabled, the user will never see this message.  If it is disabled, they will see it.

The main advantage of this approach is that there is no flicker waiting for the page to load before the message is hidden.  See the example blow.

<script type=”text/javascript”>document.write(‘<div style=”display:none”>’);</script>
You must enable JavaScript to use this site
<script type=”text/javascript”>document.write(“</div>”);</script>

Update: As pointed out in the comment thread, this is the same as <noscript> really, but no harm in having one more pattern out there


6 Responses to “Displaying a ‘JavaScript is Required’ message”

  1. Will said

    What about ?

  2. Will said

    uck, stripped out the tag…

    What about <noscript>?

  3. Hi Will,

    noscript is fine too – this is just another way of doing it, for no particular reason 🙂


  4. bob said

    Isn’t this re-inventing the wheel somewhat? That’s exactly what the noscript tag is intended to achieve.

  5. Wiggins said

    Useful when using XHTML because the noscript tag is not supported in XHTML (see

  6. Magical. So nice.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: