spacer

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

home / experts / javascript / column23


Behavior Handler's attachNotification Method

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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