DOM2 Events - Installation

  1. Add the following code to the document you want to use the script in (before any calls to the functions defined in the script):

    <script type="text/javascript" src="dom2_events.js"></script>

    If the dom2_events.js file is in a different directory than the html document, be sure to include the relative path to the Javascript file in the src attribute value.

  2. Write your event listener registration and event handlers assuming you are supporting Mozilla only (ie, use only DOM2 event properties and methods).

  3. Before attaching event listeners to any objects in the document (with element.addEventListener()), call DOM2Event.initRegistration() to allow event listener registration on any or all elements in the document.

  4. Add the following line as the first line in every event handler function:

          event = new DOM2Event(event, window.event, this);

    The first argument to the DOM2Event() constructor must be the parameter of the containing event handler function (this contains the event object in Mozilla). For instance, if the parameter to your event handler is evt (ie, the first line of the function definition is function handleEvent(evt)), this line will read:

          event = new DOM2Event(evt, window.event, this);

    You can also rename the variable that the DOM2Event object is assigned to if you like. This variable contains the event object for your event handler.

  5. Have a nice day.

More about this script

Related to this script


This script is released under a Creative Commons License.