Main Page Content
Javascript Debugging Part 1 Of 3
Undoubtedly, when writing a new script or trying to tweak a once-working script to suit your needs better, you've run into instances where your attempts have gone up in a fiery ball of flames; maybe you misspelled a variable, were trying to reference an object that didn't yet exist, or were using a reserved word. Whatever the problem, the quickest way to finding out where the problem lies is to see the errors your script produced. Using the information in the error, you can locate it easier and understand better what you need to fix. There are different ways of going about determining the errors depending on the browser you're using. I will attempt to cover all the tricks you'll need to get this working in Netscape Navigator 4.06/4.5+ (The JavaScript Console was introduced with JavaScript 1.3 in Netscape Navigator 4.06 & 4.5) and Internet Explorer 4+ to suit your needs and particular working style.By default, the JavaScript console/alerts aren't displayed in either of the browsers we're covering, unlike earlier versions of Internet Explorer and Netscape Navigator 4. While this makes for a smoother viewing experience, it will make your development process very frustrating. The only clue you'll have that an error occurred is an error warning in the status bar (see below). However, if you prefer to have the errors automatically displayed, there are four easy ways in Netscape Navigator and two easy ways in Internet Explorer to view JavaScript errors.
Netscape Navigator JavaScript Error Warning
Internet Explorer JavaScript Error Warning
Netscape Navigator JavaScript Error Warning
Internet Explorer JavaScript Error Warning
Using Netscape 4+
- Type
JavaScript:
into the location bar of your browser. - Drag the link below to your Personal toolbar. To see any errors, simply click the Display Errors button on your Personal toolbar.
- Edit your preferences so the new JavaScript console automatically opens when an error occurs.
- Quit Communicator before doing this, otherwise your changes will be lost.
- Open your Navigator preferences file (prefs.js), normally located in whichever folder your user profile is stored.
- Add the following line to the file:
user_pref("javascript.console.open_on_error",true);
- Save and restart Communicator.
- Edit your preferences so the traditional JavaScript alert window automatically opens when an error occurs.
- Quit Communicator before doing this, otherwise your changes will be lost.
- Open your Navigator preferences file (prefs.js), normally located in whichever folder your user profile is stored.
- Add the following line to the file:
user_pref("javascript.classic.error_alerts",true);
- Save and restart Communicator.
Using Internet Explorer 4+
- You can double click the status bar to find out what the error was and what line it occurred on if you notice one of the messages below and a warning icon as illustrated above.
Done
Error on page
Done, but with errors on page
- If you'd prefer to get notification of every error, then turn error notification on.
- Make sure
Display a notification about every script error
under the Advanced tab of your Internet Options is checked. - Make sure
Disable Script Debugging
under the Advanced tab of your Internet Options is unchecked.