Zeus web server - 725Chapter 29 .Event Objects Event Handler Location IE4+/Windows
725Chapter 29 .Event Objects Event Handler Location IE4+/Windows IE4+/Macintosh NN6 BODY yes yes yes HTML yes no yes document yes yes yes window no no yes Despite the discrepancies in Table 29-1, events do bubble through the most likely HTML containers that come to mind. The object level with the most global scope and that works in all browser categories shown in the table is the document object. Preventing IE event bubbling Because bubbling occurs by default, there are times when you may prefer to prevent an event from bubbling up the hierarchy. For example, if you have one handler at the document level whose job is to deal with the clickevent from a related series of buttons, any other object that receives clickevents will allow those events to bubble upward to the document level unless the bubbling is cancelled. Having the event bubble up could conflict with the document-level event handler. Each eventobject in IE has a property called cancelBubble. The default value of this property is false, which means that the event bubbles to the next outermost container that has an event handler for that event. But if, in the execution of an event handler, that property is set to true, the processing of that handler finishes its job, but the event does not bubble up any higher. Therefore, to stop an event from bubbling beyond the current event handler, include the following statement somewhere in the handler function: event.cancelBubble = true You can prove this to yourself by modifying the page in Listing 29-5 to cancel bubbling at any level. For example, if you change the event handler of the FORM element to include a statement that cancels bubbling, the event goes not further than the FORM in IE (the syntax is different for NN6, as discussed later):