Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Ajax and JavaScript

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Viewing Script Errors

Sometimes, the JavaScript you and I write will have errors in it. (Well, maybe not you, but it sure happens to me.) The two browsers we're working with have the ability to tell us what the error is, and that's a useful thing to know in this chapter, where we're establishing our JavaScript foundation.

For example, what if we had misspelled document.write as documnt.write in our first script? Here's how that would look:

      Our first script!

    <H1>Here we go!</H1>
    <SCRIPT LANGUAGE="JavaScript">
      documnt.write("Hello from JavaScript!")
      // -->

Both browsers would have trouble with this JavaScript. If there's a JavaScript error in the Internet Explorer, you'll see a small icon at right in the status bar at the bottom of the browser (see Figure 1.8). Double-clicking that icon opens an error dialog box, as you also see in Figure 1.8, telling you what the error is.

Figure 1.8 Locating an error in the Internet Explorer.

In fact, you can have a dialog box come up automatically for every error. In the Internet Explorer 6, you do that with the Tools | Internet Options | Advanced | Browsing item, and select the check box labeled Display a Notification About Every Script Error.

In the Netscape Navigator version 4 and later up to 6, you'll see a message in the status bar indicating that there is an error and directing you to navigate to the URL "javascript:". To do that, you can use the File | Open Page menu item, opening the Open Page dialog box. Type javascript: into that dialog box and click the Open button. This opens the JavaScript console, which is a separate window that displays errors.

In Netscape Navigator 6, you don't see an error icon in the taskbar if there's an error. If your script isn't running as it should, however, select the Tasks | Tools | JavaScript Console item to open the JavaScript console window. You can even leave this window open as you continue to work in the browser. You can see the JavaScript console for Netscape Navigator 6 in Figure 1.9.

Locating errors like this can be invaluable in helping you deal with them, and it's a good foundation item for our foundation chapter.

Figure 1.9 Locating an error in the Netscape

  • + Share This
  • 🔖 Save To Your Account