Behaviors > Behaviors overview |
Behaviors allow visitors to interact with a Web page to change the page in various ways, or to cause certain tasks to be performed. A behavior is a combination of an event with an action triggered by that event. In the Behaviors panel, you add a behavior to a page by specifying an action and then specifying the event that triggers that action.
Events are, effectively, messages generated by browsers indicating that a visitor to your page has done something. For example, when a visitor moves the pointer over a link, the browser generates an onMouseOver
event for that link; the browser then checks to see whether there's some JavaScript code it's supposed to call when that event is generated for that link. Different events are defined for different page elements; for example, in most browsers onMouseOver
and onClick
are events associated with links, whereas onLoad
is an event associated with images and with the body
section of the document.
An action consists of prewritten JavaScript code that performs a specific task, such as opening a browser window, showing or hiding a layer, playing a sound, or stopping a Shockwave movie. The actions provided with Macromedia Dreamweaver are carefully written by Dreamweaver engineers to provide maximum cross-browser compatibility.
After you attach a behavior to a page element, whenever the event you've specified occurs for that element, the browser calls the action (the JavaScript code) that you've associated with that event. (The events that you can use to trigger a given action vary from browser to browser.) For example, if you attach the Popup Message action to a link and specify that it will be triggered by the onMouseOver
event, then whenever someone points to that link with the mouse pointer in the browser, your message pops up in a dialog box.
A single event can trigger several different actions, and you can specify the order in which those actions occur.
Dreamweaver provides about two dozen behavior actions; additional actions can be found on the Macromedia Exchange Web site as well as on third-party developer sites. (See Downloading and installing third-party behaviors.) You can write your own behavior actions if you are proficient in JavaScript. For more information on writing behavior actions, see Extending Dreamweaver.
Note: The terms behavior and action are Dreamweaver terms, not HTML terms. From the browser's point of view, an action is just like any other piece of JavaScript code.