• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Script Setup > The HTML Document and JavaScript

2.1. The HTML Document and JavaScript

Unlike shell and Perl scripts, JavaScript scripts are not stand-alone programs. They are run in the context of an HTML document. When programming on the client side, the first step will be to create an HTML document in your favorite text editor, such as UNIX vi or emacs, or Windows Notepad[1] or WordPad. Since the file you create is an HTML document, its name must include either an .html or .htm extension. JavaScript programs are embedded within the HTML document between the <script> and </script> tags. Please note that throughout the code examples in this book, any whitespace shown at the beginning of the lines is only for easier readability and you should not type it in your actual file. The following example is an HTML file containing JavaScript code:

[1] If you are using Windows Notepad, be sure to turn off word wrap (under the Format menu) to avoid errors in your program.

<html><head><title>Hello</title></head>
<body>
<script language="JavaScript">
    <!-- Hide script from old browsers.
    document.write("Hello, world!");
    // End the hiding here. -->
</script>
<p>So long, world.
</body>
</html>


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint