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):

Redirecting events Starting with IE5.5, you can redirect an event to another element, but with some limitations. The mechanism that makes this possible is the fireEvent()method of all HTML element objects (see Chapter 15). This method isn t so much redirecting an event as causing a brand-new event to be fired. But you can pass most of the properties of the original eventobject with the new event by specifying a reference to the old event object as the optional second parameter to the fireEvent() method. The big limitation in this technique, however, is that the reference to the target element gets lost in this hand-off to the new event. The srcElement property of the old event gets overwritten with a reference to the object that is the target of the call to fireEvent(). For example, consider the following onClick event handler function for a button inside a FORM element:
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply