Internet Explorer 5.0, Part II: Behavior Handler's attachNotification Method - Doc JavaScript
Behavior Handler's attachNotification Method
There are several ways to communicate between the host page and the behavior scriptlet. Event-based communication is described later in this column. The other mechanism by which the caller document can pass information to the scriptlet is by passing a parameter to a pre-defined function of the scriptlet. You specify the function name in the scriptlet body, using the attachNotification()
method:
BehaviorID.attachNotification(notificationFunction)
where BehaviorID
is the ID of the relevant Behavior
, as specified in the Behavior-type Implements
element of the behavior scriptlet, and notificationFunction
is a user-defined function, written in the scriptlet body.
The notification function should have one parameter. The caller document passes one of the following possible values to the notification fucntion:
- "contentChange". This value fires whenever there is a change in the content of an element where the behavior applies. It may be the parsing of the closing tag of the element, or when a script sets its
innerHTML
property. A behavior can wait for this notification and then, upon notification, retrieve the content of the element it is applied to. - "documentReady". This value fires when the document has completely loaded. Any required initialization and modification to the document should follow the "documentReady" state. As far as changes to the element's
style
are concerned, we recommended to make them in the body of the scriptlet's<SCRIPT>
block. Making these changes in the notification function may cause slight flashing, and should be avoided.
attachNotification()
method, we can replace the attachEvent()
statement with an attachNotification()
one. In its current version, the scriptlet attaches the "onload"
event to the window
object:
window.attachEvent("onload", onload);
and the onload()
function is defined as follows:
function onload() {
loadEvent = createEventObject();
loadEvent.id = uniqueID;
fireEvent("onBoxLoad",loadEvent);
}
Instead, we can communicate the notification function name to the caller document:
window.attachNotification(onload);
and define the onload()
function as follows:
function onload(event) {
if (event=="contentChange") {
loadEvent = createEventObject();
loadEvent.id = uniqueID;
fireEvent("onBoxLoad",loadEvent);
}
}
Created: August 11, 1998
Revised: August 11, 1998
URL: https://www.webreference.com/js/column23/notify.html