DOM2 Events - Description

Though DOM1 help standardize many aspects of document object models, events weren't tackled until DOM2. Mozilla implements the DOM2 Events module but IE 5 and 6 do not. The capabilities of the IE event model is not vastly different from the DOM2 event model - IE supports event listeners through proprietary registration methods and the values of many DOM2 event properties can be determined through IE event properties. As such, many DHTML applications support both Mozilla and IE but use lots of branching in event handler functions.

This script allows authors to avoid all this branching and use DOM2 event properties and methods to register event listeners and deal with event objects as if they were coding a Mozilla-specific application.

Because IE Mac doesn't allow expando properties on event objects (version 1 of this script used this approach), this script creates a synthetic event object and copies all the event properties and methods to this object. Along the way, mis-implemented and buggy properties are fixed (timeStamp, clientX and clientY).

I've also added a couple of non-standard but very helpful properties to the event object - keyCode for keyboard events, and pageX and pageY for mouse events.

Though this script is aimed specifically at IE5+ so that people can author DHTML applications that support IE5 and Mozilla, I've included (and I hope it works) code to support Opera 5+, Konqueror 2.2+, Safari, and iCab 2.7 (mostly based on PPK's DOM Compatibility Tables)

For more on the W3C DOM2 Events module and how events work, consult a good DOM reference.

Script Engine / Document Object Model Required

( Javascript 1.1 | JScript 2.0 | ECMAScript 1.0 ) & DOM 1 & ( Gecko event model | MSIE event model )

Modification History

2002/11/28 v1.0


2003/03/05 v1.0.1

Bug fixes for Event.stopPropagation() and Event.preventDefault().

2003/03/14 v2.0

Rewrote to use a synthetic event object.

2004/01/20 v2.0.1

Fixed propagation bug in Mozilla (thanks Eric).

More about this script

Related to this script


This script is released under a Creative Commons License.