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:
<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> 2.1.1 Script ExecutionSince a JavaScript program is embedded in an HTML document, you will execute it in your browser window. If using Netscape Navigator or Internet Explorer, follow these instructions:
|