The <noscript> Tag

While the vast majority of users visiting your site will have JavaScript enabled - according to The Counter the current proportion is around 95% - you need to cater for the small number of users who will choose to disable scripting. The classic way of doing this is by placing the <noscript>..</noscript> tag pair directly into the body section of a webpage. We have on occasion used a more elegant technique. The code

<noscript>
<meta http-equiv="refresh" content="0; url=http://www.yoursite.com/noscripts.html"/>
</noscript>

is placed in the head section of every page accessible from this site. This ensures that the viewer is redirected to the noscripts page if JavaScript has been disabled in his/her browser. The HTML for our noscripts page is given below

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
        <head>
            <meta name="description" content="JavaScript Disabled!">
            <meta http-equiv="refresh" content="5;url=http://www.yoursite.com">
            <title>Please Enable JavaScript!</title>
        </head>
        <body>
           <pre>Dear Visitor,
           
               Thank you for...
           </pre>    
        </body>
      </html>
    

The message regarding the need to enable JavaScript is nothing out of the ordinary. However, note the use of the meta refresh tag in the document header. This causes the YourSite home page, index.shtml, to be reloaded every five seconds. If scripting continue to be disabled the refresh embedded in the noscript tag on the index.shtml page will cause noscripts.html to be displayed all over again.

While it is allowed by default, IE7 enables users to turn off meta refresh. Consequently this technique for providing feedback regarding the need to enable scripting will not work with a very small proportion of visitors to the site. In our experience this number is too small to be of any significance.

A note of caution if you are considering using this technique - the code could send some search engine spiders into a loop whereby they read your <noscript> code and never get any further. Not all spiders are susceptible but it is best not to use this technique for pages which you want to get indexed.

Jump To...

Colophon