• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 16. Behavior Modification > Debugging Your JavaScript

Debugging Your JavaScript

New in Dreamweaver 4 is a JavaScript Debugger, which allows you to find problems in your JavaScript code. Even if you are just using the built-in behaviors, there are times when they don't do exactly what you expect, and the debugger can be a valuable tool to find the problem.

Using the JavaScript Debugger

Open the page with the JavaScript you want to debug.

Select File > Debug in Browser > Netscape (or Internet Explorer), or select an option from the Code Navigation menu on the Code inspector toolbar. A browser window will open, and a Java Security window will open as well.

If you are debugging in Netscape Navigator, click on OK in the debugger warning box that appears, then click on Grant in the Java Security dialog box. If you are using Internet Explorer, click on Yes in the Java Security dialog box, then on OK in the debugger warning box that appears (Windows only; the debugger does not work on Internet Explorer for Macintosh).

The Debugger window will appear ( Figure 16.73 ), and the browser will stop at the first line of JavaScript code.

Figure 16.73. The Debugger window allows you to follow along in your code as it runs.

If you think you've identified where something is going wrong, click on the line of code preceding that area and add a breakpoint by clicking the Set/Remove Breakpoint button or by pressing F7.

You can also set a breakpoint in the Code inspector by selecting Set Breakpoint from the {} Code Navigation menu.

Click on the Run button . The code will start executing, and then stop at the point at which you set the breakpoint.

Click the Step Into button (or press F10). This will step through one line of your code at a time ( Figure 16.74 ). You can watch what happens in the browser window with each step.

Figure 16.74. Setting a breakpoint allows you to stop your code to take a look at what's happening.

Repeat step 7 until you find your error or pass the problem area.

Sometimes simply stepping through your code is not enough to figure out what's wrong. You can also watch the values of variables (and even set them) in the Debugger window as well.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint