Events let you know when a user is doing something or when a page has loaded. Catching and handling events lets your code do the right thing at the right time, serving the users of your programs. Regardless of why they happen or how they're implemented, events in JavaScript are associated with objects and are not intrinsic to the language itself. Typically, when working with browsers, events are related to the DOM implemented in each browser. There is a default behavior associated with each event, but events can be used to modify functionality or add additional functionality. Extending the event behavior can be managed within the (X)HTML tag for the object, or in a separate JavaScript code block or file. The events themselves are fairly intuitive. The W3C (World Wide Web Consortium) categorizes events into three distinct areas: user interface (mouse, keyboard), logical (result of a process), and mutation (action that modifies a document). The basic events, affected objects, and descriptions are listed in Table 6-1.
There are some proprietary events that aren't listed; they'll be covered in the text. Also, up to this point, most of the examples and material we've covered have been cross-browser-safe. By this I mean that most modern browsers (Netscape and IE 4.x and up, or 2002 and later) support what's been covered, and the examples work as detailed in this book. Events are the first topic we'll cover that differs between browsers and browser generations. Not just differdiffer with a vengeance. Event handling in JavaScript has gone through more than one generation, as well as undergoing proprietary extensions. Many older iterations are still supported for reasons of backward compatibility, and many of the newer event models are not universally implemented across all popular browsers. In this section, we'll start by looking at event systems from oldest to newest. At the end of each, browser compatibilities and quirky behaviors are listed. |