Table of Contents | Previous | Next | Index


Appendix B
Displaying Errors with the JavaScript Console

This appendix describes how to use the JavaScript console to evaluate expressions and display error messages to the user.

This appendix contains the following sections:

JavaScript 1.2 and earlier versions. The JavaScript console is not available.


Opening the JavaScript Console

To open the JavaScript console, do one of the following. The console opens in a new window.


Evaluating Expressions with the Console

The JavaScript console is a two-frame window. The lower frame contains a field labeled javascript typein, where you can type one-line expressions. You can use this field to assign values to variables, test comparison operators, and perform math operations.

To evaluate an expression:

  1. Type the expression into the javascript typein field.
  2. Press Return.
  3. The results are displayed in the upper frame.

For example, you could evaluate the following expressions:

alert("hello there")      // Displays an alert dialog box
5-2                       // Displays "3" in the upper frame
var high=100; var low=45; // Creates two variables
high-low;                 // Displays 55 in upper frame

Displaying Error Messages with the Console

When a JavaScript error condition is encountered in the client (for example, on an HTML page or within an email message), a dialog box is displayed describing the error (for example, Line 64: myVariable is not defined). For most users, these errors are incomprehensible, and dismissing the dialog box becomes annoying. The only people likely to be interested in the errors are JavaScript developers, testers, and sophisticated users.

You can force JavaScript errors to be displayed only in the JavaScript console. Then, when a JavaScript error occurs, the error message is directed to the console, and no dialog box appears. Since the console is normally not displayed, the user receives no direct indication that a JavaScript error has occurred. If a user or developer wants to view a JavaScript error, they need to open the console.

The text of JavaScript error messages appears the same way whether they are displayed in the console or in the traditional error dialog box.

JavaScript error descriptions are always displayed in English regardless of the locale.

Setting Preferences for Displaying Errors

You can specify whether to automatically open the console when a JavaScript error occurs or to display a dialog box for each JavaScript error. To set preferences for displaying errors, modify the Navigator preference file prefs.js as follows.

  1. Make sure Navigator is not running.
  2. Navigator may overwrite your changes if it is running when you edit the preferences.

  3. Open prefs.js.
  4. The preference file is in the user's directory under the Netscape/Users directory. For example, on Windows NT, you may find prefs.js in the following location:

    <Netscape path>\Users\<user name>

  5. Add one of the following lines to prefs.js:
  6. Save and close prefs.js.

Table of Contents | Previous | Next | Index

Last Updated: 05/27/99 21:21:50

Copyright (c) 1999 Netscape Communications Corporation