Registers an event handler for the specified event type.
HRESULT addEventListener( BSTR type, IDispatch *listener, VARIANT_BOOL useCapture );
- [in] The type of event type to register.
- [in] The event handler function to associate with the event. Be aware that the event handler function itself requires two parameters - the first is the event target (that is, the object on which the event handler function is being invoked) and the second is the IDOMEvent object.
- [in] A VARIANT_BOOL value that specifies the event phase to add the event handler for:
- Register the event handler for the capturing phase.
- Register the event handler for the bubbling phase.
Returns S_OK if successful, or an error value otherwise.
Events are handled in two phases: capturing and bubbling. During the capturing phase, events are dispatched to parent objects before they are dispatched to event targets that are lower in the object hierarchy. During the bubbling phase, events are dispatched to target elements first and then to parent elements. You can register event handlers for either event phase. For more information, see IDOMEvent::eventPhase.Note Some events, such as onfocus, do not bubble. However, you can capture all events. You cannot capture events by elements that are not parents of the target element.
If you register multiple identical event handlers on the same event target, the duplicate event handlers are discarded.