Visits to this blog

Displaying a ‘JavaScript is Required’ message

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