Web hosting reviews - 718 Part III . Document Objects Reference Listing

718 Part III . Document Objects Reference Listing 29-2 (continued) NAME= layerButton2 onClick= alert( Event finally reached Button: + this.name) >

Passing events toward their targets If you capture a particular event type, your script may need to perform some limited processing on that event before letting it reach its intended target. For example, perhaps you want to do something special if a user clicks an element with the Shift metakey pressed. In that case, the function that handles the event at the document level inspects the event s modifiers property to determine if the Shift key was pressed at the time of the event. If the Shift key was not pressed, you want the event to continue on its way to the element that the user clicked. To let an event pass through the object hierarchy to its target, you use the routeEvent() method, passing as a parameter the event object being handled in the current function. A routeEvent() method does not guarantee that the event will reach its intended destination, because another object in between may have event capturing for that event type turned on and will intercept the event. That object, too, can let the event pass through with its own routeEvent()method. Listing 29-3 demonstrates event routing by adding onto the document being built in previous examples. While the clickable button objects are the same, additional powers are added to the document and layer function handlers that process events that come their way. For each of these event-capturing objects, you have additional checkbox settings to allow or disallow events from passing through after each level has processed them. The default settings for the checkboxes are like the ones in Listing 29-2, where event capture (for the click event) is set for both the document and layer objects. Clicking any button causes the document object s event handler to process and none other. But if you then enable the checkbox that lets the event continue, you find that click events on the layer buttons cause alerts to display from both the document and layer object event handler functions. If you then also let events continue from the layer object, a click on the button displays a third alert, showing that the event has reached the buttons. Because the main1 button is not in the layer, none of the layer object event handling settings affect its behavior. Listing 29-3: NN4 Capture, Release, and Route Events