12.5.1 Adding Scripts to Documents
126.96.36.199 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.
<img src="mybutton.jpg" onMouseDown="MM_callJS('window.close( )')">
However, if you choose the onClick event, which cannot be applied to an <img> tag, instead of the onMouseDown event, Dreamweaver automatically wraps the <img> tag in a null link, such as in:
Applying a behavior in Dreamweaver adds the JS code directly to your HTML document, which can be inefficient. Although Dreamweaver is smart enough not to duplicate JS code within a single document, it duplicates the code if you use the same behavior on more than one page. To add scripts to a web page based on a template, place scripts in an external .js file and link to it from the template.
First, let's talk about scripts embedded within your document's HTML code. To open the Property inspector, double-click the script icon in either the Document window or the Head Content bar (as described in the preceding section). Click the Edit button in the Property inspector to open the Script Properties dialog box, shown in Figure 12-5.
Figure 12-5. The Script Properties dialog box
After editing your script, save your changes by clicking the OK button or discard changes using the Cancel button. Of course, you can also hand-edit your scripts in Code view or the Code Inspector; the Script Properties dialog box is just a convenient way to edit the <script> tag in isolation.
188.8.131.52 Editing external JS files in the Code view editor
External code cannot be edited in the Script Properties dialog box; however, click the Edit button in the Property inspector to edit it in the Code view window, as seen in Figure 12-6.
Figure 12-6. Code view for external scripts
The Edit button in the Property inspector opens Code view only if there are no embedded scripts within the HTML file. If you've used both linked and embedded scripts in the same HTML file, use the File Open command to open the .js or .vbs file instead.
When using Code view to edit an external script, many of Dreamweaver's menu options are disabled. The options available in this mode are listed in Table 12-5.