Web site developers - 99Chapter 14 .Document Object Model Essentials Handling events

99Chapter 14 .Document Object Model Essentials Handling events Thanks to the W3C DOM s event model implementing a similar event bubbling scheme as IE4+, you can apply that event propagation model to IE4+ and W3C DOM browsers. There are differences in the details, however. IE s approach does not pass the event object as a parameter to a function invoked by an event handler. Instead, the IE eventobject is a property of the window object. Therefore, your functions have to look for the passed parameter and substitute the window.event object in its place for IE: function calculate(evt) { evt = (evt) ? evt : window.event // more statements to handle the event // } Additional branching is necessary to inspect many details of the event. For example, IE calls the object receiving the event the srcElement, while the W3C DOM calls it the target. Canceling the default behavior of the event (for example, preventing a form s submission if it fails client-side validation) is also different for the models (although the old-fashioned way of letting HTML-type event handlers evaluate to returnfalse still works). You can find more event object details in Chapter 29. Simulating IE4+ Syntax in NN6 With so much IE4+ DHTML-related JavaScript code already in use, scripters are certainly eager to leverage as much of their old code as possible in W3C DOM browsers such as NN6. While NN6 helps a bit by implementing the IE innerHTML property for HTML elements, this section shows you how a simple .js library can provide NN6 with a few more common convenience properties of the IE4+ object model. By linking this library into your pages, you can give NN6 the valuable HTML element properties shown in Table 14-8. Table 14-8 IE4+ HTML Element Property Simulation for NN6 Property Read Write Replaces in W3C DOM all yes no getElementsByTagName( * ) innerText yes yes nodeValue property for text nodes; creating a text fragment node and inserting it into existing node structure outerHTML no yes (No equivalent) Scripts that make these simulations possible use the prototype inheritance behavior of static objects described earlier in this chapter. Because they require
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Leave a Reply