User Guide
The Behaviors API 237
The Behaviors API
Two Behaviors API functions are required (applyBehavior() and behaviorFunction()); the
rest are optional.
applyBehavior()
Description
This function inserts into the user’s document an event handler that calls the function that the
behaviorFunction() function inserts. The applyBehavior() function can also perform other
edits on the user’s document, but it must not delete the object to which the behavior is being
applied or the object that receives the action.
Arguments
uniqueName
• The argument is a unique identifier among all instances of all behaviors in the user’s
document. Its format is
functionNameInteger, where functionName is the name of the
function that
behaviorFunction() inserts. This argument is useful if you insert a tag into the
user’s document and you want to assign a unique value to its
NAME attribute.
Returns
Dreamweaver expects a string that contains the function call to be inserted in the user’s
document, usually after accepting parameters from the user. If the
applyBehavior() function
determines that the user made an invalid entry, the function can return an error string instead of
the function call. If the string is empty (
return "";), Dreamweaver does not report an error; if
the string is not empty and not a function call, Dreamweaver displays a dialog box with the text
Invalid input supplied for this behavior: [the string returned from
applyBehavior()]. If the
return value is
null (return;), Dreamweaver indicates that an error occurred but gives no
specific information.
Note: Quotation marks ("")within the returned string must be preceded by a backslash (\) to avoid
errors that the JavaScript interpreter reports.
Example
The following example of the applyBehavior() function returns a call to the
MM_openBrWindow() function and passes user-specified parameters (the height and width of the
window; whether the window should have scroll bars, a toolbar, a location bar, and other features;
and the URL that should open in the window):
function applyBehavior() {
var i,theURL,theName,arrayIndex = 0;
var argArray = new Array(); //use array to produce correct ¬
number of commas w/o spaces
var checkBoxNames = new Array("toolbar","location",¬
"status","menubar","scrollbars","resizable");
for (i=0; i<checkBoxNames.length; i++) {
theCheckBox = eval("document.theForm." + checkBoxNames[i]);
if (theCheckBox.checked) argArray[arrayIndex++] = ¬
(checkBoxNames[i] + "=yes");
}
if (document.theForm.width.value)
argArray[arrayIndex++] = ("width=" + ¬