spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column23


Behavior Handler's attachNotification Method

Developer News
HP to Microsoft: Thanks for Nothing
iPhone Remains Left Out as Android Scores Flash
The Year of Living the OpenSocial

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.
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

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Gateway Launches New Core i7-powered FX-Series Gaming PCs · Review: Lenovo ThinkPad SL300 · EBay, Alternative Site Holiday Resources for Sellers


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

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