Inserting JavaScript

Dreamweaver includes many fun and useful interactive effects—Spry menus, Spry form validation, Spry effects, Dreamweaver behaviors, and so on. JavaScript is the “engine” behind all of them. Of course, you can do a lot of other cool things with JavaScript that Dreamweaver hasn’t programmed. In these cases, you need to wade into the depths of JavaScript programming yourself.

The most straightforward approach, especially if you’re familiar with JavaScript, is to simply switch into Code view (Ctrl+` [Option-`]), and then code away. If you prefer, you can use Dreamweaver’s Script window to add JavaScript code (see Figure 7-21).

Unlike Code view, the Script window doesn’t respond to the Tab key; if you’re accustomed to indenting your code, you need to use spaces. You can also insert a message in the “No script” box, which appears if the web browser doesn’t understand JavaScript.

Figure 7-21. Unlike Code view, the Script window doesn’t respond to the Tab key; if you’re accustomed to indenting your code, you need to use spaces. You can also insert a message in the “No script” box, which appears if the web browser doesn’t understand JavaScript.

To add JavaScript code, click in either the head or body section of a page and then choose Insert→HTML→Script Objects→Script. In the Script window that appears, from the Type menu, choose “none” if you’re working on an HTML5 page or “text/javascript” for XHTML or HTML 4 pages.

Tip

You can use the Insert Script command in Design view also, but to add a script to the <head> of a page, first choose View→Head Content, which opens a small bar below the Document toolbar that lists all the ...

Get Dreamweaver CS6: The Missing Manual now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.