User Guide
The Behaviors API 243
The returned dimensions are smaller than the size of the entire dialog box because they do not
include the area for the OK and Cancel buttons. If the returned dimensions do not accommodate
all options, scroll bars appear.
Example
The following instance of windowDimensions() sets the dimensions of the Parameters dialog box
to 648 x 520 pixels:
function windowDimensions(){
return "648,520";
}
What to do when an action requires a return value
Sometimes an event handler must have a return value (for example,
onMouseOver="window.status='This is a link'; return true"). But if Dreamweaver
inserts the
"return behaviorName(args)" action into the event handler, behaviors later in the
list are skipped.
To get around this limitation, set the
document.MM_returnValue variable to the desired return
value within the string that the
behaviorFunction() function returns. This setting causes
Dreamweaver to insert
return document.MM_returnValue at the end of the list of actions in
the event handler. For an example about using the
MM_returnValue variable, see the Validate
Form.js file in the Configuration/Behaviors/Actions folder within the Dreamweaver
application folder.
A simple behavior example
To understand how behaviors work and how you can create one, it’s helpful to look at an example.
The Configuration/Behaviors/Actions folder inside the Dreamweaver application folder contains
examples, but many are too complex except for the most advanced developers. Start with the
simple Action file Call JavaScript.htm (along with its counterpart, Call JavaScript.js, which
contains all the JavaScript functions).
The following code presents a relatively simple example. It checks the brand of the browser and
goes to one page if the brand is Netscape Navigator and another if the brand is Microsoft Internet
Explorer. This code can easily be expanded to check for other brands such as Opera and WebTV
and modified to perform actions other than going to URLs.
<!DOCTYPE HTML SYSTEM "-//Macromedia//DWExtension layout-engine 5.0//dialog">
<html>
<head>
<title>behavior "Check Browser Brand"</title>
<meta http-equiv="Content-Type" content="text/html">
<script language="JavaScript">
// The function that will be inserted into the
// HEAD of the user's document
function checkBrowserBrand(netscapeURL,explorerURL) {
if (navigator.appName == "Netscape") {
if (netscapeURL) location.href = netscapeURL;
}else if (navigator.appName == "Microsoft Internet Explorer") {
if (explorerURL) location.href = explorerURL;
}
}