noscript tag

Posted in HTML | Posted on 01-06-2010-05-2008

Although the majority of web users have JavaScript enabled on their browsers, there is always that small percentage that have JavaScript disabled. This is where the noscript tag comes in to play.

You may have an essential feature on your site that requires the use of JavaScript. The user might not be aware that JavaScript is disabled on their browser. We will use the noscript tag to aware them of the situation.

Let’s copy and paste this code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<title>noscript</title>

</head>

<body>

<script type=”text/javascript”>
document.write(“JavaScript is working!”);
</script>

<noscript><div>PLEASE ENABLE JAVASCRIPT ON YOUR BROWSER</div></noscript>

</body>
</html>

When you run this, you should get a message stating “JavaScript is working!”. Now to see the noscript tag in effect, you will have to disable JavaScript on your browser. Depending on your browser; check under preferences or tools to disable JavaScript. Once you have disabled Javascript, refresh the page. You should now get an alternative message.

<noscript><div>PLEASE ENABLE JAVASCRIPT ON YOUR BROWSER</div></noscript>

Here is the line of code that displays the message. The main focus is the noscript tags. You can put anything else that you would like as an alternative for those that do not have access to JavaScript.