JavaScript

Dreamweaver works with JavaScript in a variety of ways. In addition to using JavaScript behaviors, you can link to scripts in external .js files, edit .js files directly, and debug JavaScript code.

Adding Scripts to Documents

When you apply behaviors using the Behaviors panel, Dreamweaver adds the JavaScript to the <script> tag within the <head> tag. (All scripts used throughout a site are listed in the Scripts category of the Assets panel.) If you apply the same behavior twice within the same document, Dreamweaver is smart enough not to duplicate the JavaScript code within the <script> tag. You can even modify the JavaScript functions by hand in Code view, provided you don’t change a function’s name, Dreamweaver won’t overwrite your changes even if you reapply the same behavior.

The Insert Script dialog box

The Insert Invisible Tags Scripts menu command opens the Insert Script dialog box where you can enter scripts by hand. The Script button in the Objects panel’s Invisibles category opens the same dialog box. See Section 2.7.3 in Chapter 2 for more details.

Call JavaScript behavior

The Call JavaScript behavior is used to execute a line of JavaScript code. That line can include a call to a custom function or a built-in function such as window.close(). Figure 12-4 shows the exceedingly simple dialog box that lets you enter your parameters for the Call JavaScript behavior.

Figure 12-4. The Call JavaScript parameters dialog box

Other behaviors have more complex parameters, ...

Get Dreamweaver in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.