Internet Explorer 5.0, Part II: Behavior Handler's attachNotification Method - Doc JavaScript | WebReference

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:

Although our Connect Three game does not use the 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);
  }
}

http://www.internet.com


Created: August 11, 1998
Revised: August 11, 1998

URL: http://www.webreference.com/js/column23/notify.html