Let's take a look at how we can do this.
The HTML Skeleton
Before moving on, you must be familiar with the anatomy of an HTML page. Here is the HTML code for the very basic Web:
<html> <head> <title>A Simple Page</title> </head> <body> <p>A very simple Web page indeed!</p> </body> </html>
However, you can't just place the code directly into the <head>. There's something else you must do first!
The SCRIPT Block
This block can be added anywhere inside the <head> block but is normally added at the end, before the closing </head>tag:
<html> <head> <title>A Simple Page</title> <script> </script> </head> <body> <p>A very simple Web page indeed!</p> </body> </html>
One reason the <script> block is put in the header is that by placing it here you guarantee that it is loaded before anything else, which dramatically reduces the scope for errors.
<html> <head> <title>A Simple Page</title> <script language=""> </script> </head> <body> <p>A very simple Web page indeed!</p> </body> </html>
If, for example, you wanted to write a script in VBScript, the language would be set to "vbscript":
Let's take a look at two points.
The second point is one of case sensitivity. Take a look at the following:
More on the "language" Attribute
<script language="JScript"> </script>
These comment tags are easy to add. Inside the <script> tags, insert another pair of tags, <!--and -->. All the code you write goes in between these tags and is then ignored by any browser that doesn't understand what the <script> tags mean.
It might seem strange to place anything you want the browser to use inside comment tags because these are used to prevent text on the page from being displayed. But the fact is that all the browsers that understand script also know to ignore these comment tags and proceed as though they weren't there.
To make the comment tags more obvious, oftentimes developers place some (sometimes entertaining!) comments inside these HTML comment tags telling others who might view the code what they do:
The page now looks like the following: