1. Technology
Send to a Friend via Email

Learn Javascript

Using Noscript

Join the Discussion

Questions? Comments?

More of this Tutorial

External Javascripts Quiz Yourself

Introduction

While most current browsers understand Javascript a lot of the early browsers did not. The current browsers also allow Javascript to be turned off and some people do this. There are also some people (for example those with less than perfect sight) who use programs that tell them what is on the web page rather than (or in addition to) displaying it on the screen.

What this means is that not all of the visitors to your page will see the effects of the Javascripts on your page. We need to make sure that these visitors can use our site even without Javascript.

The NOSCRIPT tag

Some pages still look perfectly okay without Javascript, perhaps some validations may not be performed before processing a form or some dynamic feature may remain static but the page itself is still perfectly usable without Javascript.

Some pages are so reliant on Javascript that there is no point in having visitors who don't have Javascript visit the page at all. Our very first tutorial showed us how we could use Javascript on the calling pages to only display the link to such a page when Javascript was supported.

There are a number of pages that fall somewhere in between. They are still reasonably usable without Javascript but don't look or function quite as nicely as they ought to. In many cases we could fix these pages by just including a few extra pieces of HTML in place of those that would have been generated by the Javascript code. Of course if we add them to the page and Javascript is enabled this would mess up our page in that situation. We need a way to tell the browser to only include the code when Javascript is not enabled.

The noscript tag is just what we need to achieve this. We just place the code that we want to display when Javascript is not supported between noscript tags and the enclosed code will only be included in browsers that either don't recognise script or noscript tags (and therefore ignore both tags just displaying what is between them instead) or which recognise the tag and also identifies that Javascript has been turned off. Here is an example:

<script type="text/javascript">
document.write('<b>Hello Javascript World</b>');
</script>
<noscript>Hello World Without Javascript</noscript>

In this example "Hello Javascript World" will be displayed in the page when the browser both supports Javascript and Javascript is enabled. If the browser doesn't support Javascript or Javascript is turned off then "Hello World Without Javascript" will be displayed instead.

Using What You Know

Sometimes you can get the page to appear to be working normally by adding something between noscript tags that will substitute for what the Javascript code would have generated. Other times you can't get the page to work as well as you would like but the content is still useful enough that you want to make it available even when Javascript is unavailable.

To avoid having those people think you have totally stuffed up your page you can use the noscript tag to place a message on the page that advises these visitors that they are missing out on the full functioning of your page because they don't use Javascript. Such a message might be coded like this:

<noscript>This page uses Javascript. Your browser either
doesn't support Javascript or you have it turned off.
To see this page as it is meant to appear please use
a Javascript enabled browser.</noscript>

Past Lessons

  1. Introduction
  2. Decision Making
  3. Functions
  4. Maintain and Test
Related Video
Using Meta Data for Search

©2014 About.com. All rights reserved.