Examples from JavaScript: The Definitive Guide

By David Flanagan

Copyright © 1997-2000, O'Reilly & Associates

The lines below list the examples included in the book JavaScript: The Definitive Guide. Click on the " View Source" link to see the source code for each one. For those examples that work as standalone programs, you can also click on the "Run" link to run them in your browser.

These programs come with no warranty of any sort. They are copyrighted material and are not in the public domain. As long as you retain the copyright notice, however, you may study, use, modify, and distribute them for any purpose.

Although you can view the example source code online, by following the links below, I recommend that you download the complete set of examples so that you can work with them on your computer locally. They are available as a zip file or as a gzipped tar file.

Example 1.1 A simple JavaScript program Run View Source
Example 1.2 An HTML form with a JavaScript event handler defined Run View Source
Example 1.3 Estimating Your Taxes with JavaScript Run View Source
Example 6.1 Defining JavaScript Functions View Source
Example 6.2 Using Functions as Data View Source
Example 6.3 Checking for the Correct Number of Arguments View Source
Example 6.4 A Multi-Argument max() Function View Source
Example 6.5 Creating and Initializing an Array View Source
Example 6.6 Using Static Variables View Source
Example 7.1 A Rectangle Object Constructor Function View Source
Example 7.2 Defining and Invoking a Method View Source
Example 7.3 Defining Methods in a Constructor View Source
Example 7.4 Defining a Class with a Prototype Object View Source
Example 7.5 Defining instance/class variables and methods View Source
Example 7.6 Defining and using the valueOf() method View Source
Example 8.1 An Array Constructor View Source
Example 9.1 Copying, Passing, and Comparing by Value View Source
Example 9.2 Copying, Passing, and Comparing by Reference View Source
Example 9.3 References Themselves are Passed by Value View Source
Example 9.4 Are Strings and Functions Compared by Value or Reference? Run View Source
Example 9.5 The assign() Method View Source
Example 10.1 A Simple JavaScript Program in an HTML File Run View Source
Example 12.1 Using the alert(), confirm() and prompt() methods Run View Source
Example 12.2 Displaying and Reporting JavaScript Errors with a Run View Source
Example 12.3 Displaying a link's destination in the status line Run View Source
Example 12.4 A digital clock in the status line Run View Source
Example 12.5 Creating an invisible frame View Source
Example 12.6 Dynamically creating and animating frames Run View Source
Example 13.1 Getting Browser Version Information View Source
Example 13.2 Extracting Arguments from a URL View Source
Example 13.3 A Navigation Bar Using the History and Location Objects View Source
Example 14.1 Creating a plain-text document Run View Source
Example 14.2 Generating XBM images with JavaScript Run View Source
Example 14.3 Listing the Links in a Document View Source
Example 14.4 A Random Hypertext Link View Source
Example 14.5 Invoking Methods of a Java applet from JavaScript View Source
Example 15.1 A Utility Class for Working with Cookies Run View Source
Example 16.1 An Animation Using Image Replacement Run View Source
Example 16.2 An Animation Using the onLoad() Event Handler Run View Source
Example 16.3 Implementing a Toggle Button with Image Replacement Run View Source
Example 17.1 An HTML Form Containing all Form Elements Run View Source
Example 17.2 Performing Form Validation Run View Source
Example 18.1 A Script Hidden from Old Browsers View Source
Example 18.2 Displaying a Message on non-JavaScript Browsers View Source
Example 18.3 Loading a JavaScript-based page only if JavaScript is supported View Source
Example 18.4 Displaying a Message with <NOSCRIPT> View Source
Example 18.5 Displaying a Message for Browsers that do not Support JavaScript 1.1 View Source
Example 18.6 A Web Page to test for JavaScript Compatibility View Source
Example 18.7 Displaying a Failure Message when using <SCRIPT SRC=> View Source
Example 19.1 Scripting the built-in Java classes Run View Source
Example 19.2 Controlling an Applet with JavaScript View Source
Example 19.3 Controlling a Plug-in from JavaScript Run View Source
Example 19.4 Using JavaScript from an Applet Method View Source
Example 19.5 A Java OutputStream for Displaying HTML in a Browser Window View Source