Understanding Behaviors

Dreamweaver behaviors are prepackaged JavaScript programs that let you add interactivity to your Web pages with ease, even if you don’t know the first thing about JavaScript. By adding behaviors, you can make your Web pages do things like:

  • Make portions of a page appear and disappear.

  • Open a new browser window to a specified size, with or without scroll bars, a status bar, a location bar, and other Web browser “chrome.”

  • Change the background color of any element on a page.

  • Pop open an alert box with an important message for your site’s visitors.

Behavior Elements

To use a behavior, you bring together three elements: an HTML tag, an action, and an event:

  • First, you select an HTML tag to apply the behavior to.

  • Next, pick an action. The action is whatever the behavior is supposed to do—such as open a new browser window or hide an element on the page.

  • Finally, you assign an event to the behavior. The event triggers the action, which usually involves a visitor interacting with your site, like clicking a Submit button on a form, moving the mouse over a link, or even simply loading the web page into the browser.

For instance, say that, when a visitor clicks a link, instead of just sending them to another page, you want a new browser window to pop up and load that linked page. In this case, the HTML tag is the link itself—an <a> tag; the action is opening another browser window and loading a Web page in it; and the event brings the two together so that, when your visitor clicks ...

Get Dreamweaver CS5: The Missing Manual 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.