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

Internet Explorer 5.0, Part II: Behavior Handler's fireEvent() Method - Doc JavaScript


Behavior Handler's fireEvent Method

You can pass two parameters from a scriptlet back to its host document : the event name and the event object. You trigger this exchange with the fireEvent() method:

BehaviorID.fireEvent(eventName[, eventObject])

If BehaviorID prefix is omitted, the default behavior (as specified in the Behavior-type Implements statement) is used.

The eventName parameter above is the name of the event as defined in the Behavior-type Implements section of the scriptlet. In our Connect Three game, this section looks like this:

<IMPLEMENTS ID="kuku" TYPE="Behavior" DEFAULT>
<EVENT NAME="onBoxLoad"/>
<EVENT NAME="onBoxClick"/>
</IMPLEMENTS>

We fire this events from inside the onclick() function:

fireEvent("onBoxClick", clickEvent);

and at the end of the onload() function:

fireEvent("onBoxLoad", loadEvent);

The second parameter of fireEvent() method is optional. It is an object that you can create inside the scriptlet (see previous page) and then read its properties back at the host document. As shown above, we transfer the clickEvent object and the loadEvent object to the calling page. These objects contains some context information related to the events. In case of the clickEvent, the host page needs to know the ID of the box clicked and the shape of the piece last placed. In case of the loadEvent, the host page needs to know the ID of the box loaded.

As explained in previous page, the event object fired by fireEvent() (the second parameter) is accessed from the host page via the window.event object. Notice that the window.event object always points to the latest object fired outside the page.

https://www.internet.com


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

URL: https://www.webreference.com/js/column23/fire.html