Events are built-in constructs that are part of the interaction between JavaScript and HTML. These constructs have been crucial to DHTML for many years. They are designed to capture and handle actions triggered by the user, such as a mouse click or the pressing of a certain key. Event handlers have been brought into the world of XUL/XBL and allow dynamic, interactive Mozilla applications. In XUL, events can exist on any attribute, and typically bubble up through the hierarchy. An event attribute of the empty string generates a JS strict warning (if this is turned on in the user preferences), and removing an event attribute from a XUL event does not remove the event listener (although it does in HTML).
The events are listed in the form on<eventName>, which is how events are used as attributes on XUL elements. The attribute contains lines of script or a function call, when a script is too long. Here is an example of an event attribute that carries out a function each time a menulist value changes:
<menulist id="eventList" editable="true" flex="1" onchange="addEvent(this)">
The syntax is different in XBL. Here the event is specified as the value of the name attribute, which is attached to the handler element. One or more of these elements can optionally be contained in a binding. The given value is the event's name, minus the "on" prefix. The executed code is contained in the body of the handler inline, or in the action attribute, as shown in this example:
<handler name="focus" action="this.activate( )"/>
Chapter 7 provides a closer look at events in XBL. All the events listed here are available for use in XUL and XBL.