Полезная информация

Table of Contents | Previous | Next | Index

Appendix C
Displaying Errors with the JavaScript Console

This appendix describes using the JavaScript Console to display error messages to the user.

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. Only JavaScript developers, testers, and sophisticated users are likely to be interested in the errors.

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

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

Opening the JavaScript Console

To open the JavaScript console, enter the following URL in the location bar, as you would any other URL.

The following HTML also opens the JavaScript console.

<A HREF="javascript:">Open JavaScript console</A>
You cannot open the JavaScript console from the browser menu.

Setting JavaScript Console Preferences

You can set preferences to automatically open the console when a JavaScript error occurs or to display a dialog box for each JavaScript error.

Set JavaScript console preferences in the Navigator preference file. The preference file is in the user's directory under the Netscape/Users directory. For example, in Windows NT, you may find the preference file prefs.js in the following location:

<Netscape path>\Users\<user name>
Make sure Navigator is not running when you edit the preferences, or it may overwrite your changes.

Opening the JavaScript Console Automatically

To automatically open the JavaScript console when a JavaScript error occurs, add the following line to your preferences file:

user_pref("javascript.console.open_on_error", true);
When a JavaScript error occurs, the console opens automatically and scrolls to the error message.

Displaying JavaScript Error Dialog Boxes

To open an error dialog box each time an error occurs, can add the following line to your preferences file.

user_pref("javascript.classic.error_alerts", true);

Table of Contents | Previous | Next | Index

Last Updated: 11/06/98 10:47:39

Copyright ╘ 1998 Netscape Communications Corporation