Examples from JavaScript: The Definitive Guide, Third Edition

By David Flanagan

Copyright © 1996, 1997, 1998 O'Reilly & Associates

The lines below list the examples included in the third edition of the book JavaScript: The Definitive Guide. Click on the "View Source" link to see the source code for each one. Some of these examples are standalone programs, that you can run by clicking on the "Run Examples" link. Other examples are not standalone programs, and you cannot run them directly. You can, however, modify them to run on their own, or you can integrate them into larger programs.

These examples come with no warranty of any kind. They are copyrighted material and are not in the public domain. You may study, use, modify, and distribute them for any purpose, as long as you retain the copyright notice at the top of each file.

If you are viewing these examples online, we recommend that you download the full set of examples and install them locally on your computer. The examples are available for download in two formats:

Download the examples in ZIP format: js3examples.zip
Download the examples in .tar.gz format: js3examples.tar.gz

1-1: A Simple JavaScript ProgramView sourceRun Example
1-2: An HTML Form with a JavaScript Event Handler DefinedView sourceRun Example
1-3: Computing Loan Payments with JavaScriptView sourceRun Example
7-1: Defining JavaScript FunctionsView source
7-2: Using Functions as DataView source
7-3: Function That Prints a Stack TraceView source
7-4: Function to Verify Correct Number of ArgumentsView source
8-1: A Rectangle Object Constructor FunctionView source
8-2: Defining and Invoking a MethodView source
8-3: Defining Methods in a ConstructorView source
8-4: Defining a Circle Class with a Prototype ObjectView source
8-5: Defining Circle Instance and Class Variables and MethodsView source
8-6: A Complex Number ClassView source
11-1: Copying, Passing, and Comparing by ValueView source
11-2: Copying, Passing, and Comparing by ReferenceView source
11-3: References Themselves Are Passed by ValueView source
11-4: Are Strings Compared by Value or by Reference?View source
11-5: An instanceOf() Method Using __proto__View source
12-1: A Simple JavaScript Program in an HTML FileView sourceRun Example
13-1: Using the alert(), confirm(), and prompt() MethodsView source
13-2: A Digital Clock in the Status LineView sourceRun Example
13-3: Determining Browser Vendor and VersionView source
13-4: Moving a WindowView sourceRun Example
13-5: Extracting Arguments from a URLView source
13-6: A Navigation Bar Using the History and Location ObjectsView source
13-7: A Frame Color AnimationView sourceRun Example
14-1: Dynamically Creating a Dialog WindowView sourceRun Example
14-2: Creating a Plain-Text DocumentView sourceRun Example
14-3: An Animation Using Image ReplacementView sourceRun Example
14-4: An Animation Using the onLoad Event HandlerView sourceRun Example
14-5: Implementing a ToggleButton with Image ReplacementView sourceRun Example
14-6: Listing the Links in a DocumentView source
14-7: Listing All AnchorsView source
15-1: An Event Monitoring ToolView sourceRun Example
16-1: An HTML Form Containing All Form ElementsView sourceRun Example
16-2: Performing Form ValidationView sourceRun Example
17-1: Defining and Using Cascading Style SheetsView sourceRun Example
17-2: Specifying Styles with JavaScript SyntaxView sourceRun Example
17-3: Dynamic Inline Styles in Internet ExplorerView sourceRun Example
17-4: Portable Dynamic HTML Elements with the DynEl ClassView source
17-5: Using the DynEl ClassView sourceRun Example
18-1: A Utility Class for Working with CookiesView sourceRun Example
19-1: A Message for Browsers that do not Support JavaScript 1.1View source
19-2: Suppressing Version-Related ErrorsView source
19-3: A Web Page to Test for JavaScript CompatibilityView source
19-4: A Script Hidden from Old BrowsersView source
20-1: Controlling an Applet with JavaScriptView source
20-2: Controlling a Plugin from JavaScriptView source
20-3: Scripting the Built-in Java ClassesView source
20-4: Using JavaScript from an Applet MethodView source
20-5: An OutputStream for Displaying HTML in a Browser WindowView source
21-1: An HTML File Prepared for SigningView source
21-2: Requesting a PrivilegeView source