Event propagation (Definition)

The means whereby events are passed up a hierarchy of objects.

Event propagation is important and handled slightly differently in Netscape versus MSIE.

Events are processed by handlers in objects that support the event and are then passed upwards, being handled as necessary as they traverse a tree. This is especially useful when a single event object represents the event as properties can be added or modified at each stage.

Propagation also saves you proliferating event handlers all over your script. It may be that you can handle all the errors you need to by attaching a handler at a high level and then waiting for events to be propagated up to it.

This would be fine apart from the fact that Netscape and MSIE model this in quite different ways. The only common factor between them is that events ultimately end up at the window or document. They arrive there by quite different means, but at least you do get one centralized opportunity to handle them.

Netscape prior to version 6.0 does it like this. First it makes a list of events that it wishes to capture. This is done with the captureEvents() method. Once the event capture bitmask is set up, you need to register some event handlers by assigning a reference to a function object to the event handler properties. Events are then only propagated by the event handler if it chooses to do so. The routeEvent() function passes the event to the next event that has signified an interest with the captureEvents() bitmask. Alternatively, you can use the handleEvent() function to pass the event to an object which will then select an appropriate handler. Event propagation in Netscape is very flexible but needs to be set up manually very carefully. Basically, events are captured at the top and passed down the tree to the leaf nodes.

MSIE implements an event propagation technique that operates in completely the opposite direction. Instead of starting the processing of events at the top of the DOM hierarchy, events start at the bottom and work their way upwards. This is more of a traditional event propagation model. If an event handler wants to inhibit the passing upwards of an event, it can do so by setting the cancelBubble property of the Event object to true. The so called Input or Raw events exhibit this bubbling effect while the Semantic events do not.

At version 6.0 of Netscape, the DOM level 2 event model is supported. This a complete reorganization of event modelling in Netscape and fits more closely with the event model in MSIE. The DOM standard appears to reach a helpful compromise though and allows for both kinds of event propagation. This event model is still undergoing some change and there are additional features at DOM level 3 which have yet to be ratified and are not implemented in any browser yet.


See also:captureEvents(), Document.captureEvents(), Document.releaseEvents(), Element.onevent, Event bubbling, Event.cancelBubble, Layer.captureEvents(), Layer.releaseEvents(), Semantic event, Window.captureEvents(), Window.handleEvent(), Window.releaseEvents(), Window.routeEvent()