Binds an event from the containing document to a function in the script component.
<attach event="eventName" handler="functionName" [for="elementName"]/>
If the for
attribute is not specified, the default value of the handler attribute is the value of the event attribute. If the for
attribute is specified, the default handler attribute value is the string generated by concatenating the for
attribute value, "_", and the event attribute value.
for
attribute are "document," "window," and "element." If the for
attribute is not included, "element" is the default and the event is assumed to be fired on the element to which the behavior is attached.In the following example, the <attach> element binds three events to functions. For example, the DHTML onmouseover element is bound to the script component's do_onmouseover function. The functions bound to the DHTML onmouseover and onmouseout events are executed only if they are fired on the element in the containing document to which the behavior is attached. The docinit function is explicitly bound to the DHTML document object's onload event.
Note A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<?XML version="1.0"?> <component id="bvrscript component1"> <registration progID="Behaviorscript component"/> <implements type="Behavior"> <attach event="onmouseover" handler="do_onmouseover"/> <attach event="onmouseout "handler="do_onmouseout"/> <attach for="window" event="onload" handler="docinit"/> </implements> <script language="JScript"> <![CDATA[ var normalColor, normalSpacing; function do_onmouseover(){ // Save original values. normalColor = style.color; normalSpacing= style.letterSpacing; style.color = "red"; style.letterSpacing = 2; } function do_onmouseout(){ // Reset to original values. style.color = normalColor; style.letterSpacing = normalSpacing; } function docinit(){ document.linkColor = "red"; } ]]> </script> </component>