VI.1. Event TypesEvents have been scriptable since the earliest scriptable browsers. The number and granularity of events have increased with the added scriptability of each browser generation. The HTML 4 and DOM Level 2 recommendations cite a group of events called "intrinsic events," which all browsers since Navigator 4 and IE 4 have in common (many of them dating back to the time of Navigator 2). These events include the click, mouseover, keypress, and load events, as well as many other common events. But beyond this list, there are a number of events that are browser specific and support the idiosyncrasies of the document object models implemented in various browser classes. By far the biggest group of browser-specific events belongs to IE 5 and latermost of those implemented only in the Windows version. Every event has a type name, such as click, keydown, and load. For example, when a user clicks a mouse button, the physical action fires a "click" event. But, as described later, you can associate an event type with an element by way of an attribute inside and HTML tag or a scriptable property of the element object. By convention (and standards), the attribute and property associated with an event adopts the event name and appends the word "on" in front of it. Thus, a button element knows to do something with a click event because it has an actionan event handler functionassigned by way of an onclick event handler attribute or scripted property. As you'll see, these aren't the only ways to assign event functions to events, but they are the ways that are completely backward compatible to even the earliest scriptable browsers. You will likely encounter plenty of existing code that assigns event handler functions to events via attributes in HTML tags. Even though this approach runs counter to the modern practice of removing behaviorial items from markup, the "old fashioned" way of doing it continues to be supported by the newest browsers. A tradition among early scripters was to capitalize the first letter of the event type, as in onClick. XHTML validation, however, requires all lowercase letters for event attributes, as in onclick. In other situations, you can assign an event as a property of an object. In this case, the event property name must be all lowercase to be compatible across platforms (because scripted items, such as property and method names, are case-sensitive in JavaScript). The trend, therefore, is toward all lowercase event attribute names in tags if you choose to make assignments in that fashionthe format used throughout this writing for some demonstrations. Table VI-1 is a summary of all the events that are implemented in common for the IE 4, old Netscape Navigator, and W3C DOMs (the W3C DOM picks up HTML 4 events). Numbers in the browser columns (Netscape Navigator, Internet Explorer for Windows, and Internet Explorer for Macintosh) indicate the version in which the event was first supported. Most of these events are part of the HTML and XHTML recommendations, and will validate as lowercase attributes for elements in XHTML-Strict. A handful of other events are not part of the formal standards, but have been available in scriptable browsers since the early days. See Chapter 3 of Dynamic HTML, Third Edition for complete details about each event type.
Beyond the cross-browser events in Table VI-1, Microsoft implements an additional set that allows DHTML scripts to react to more specific user and system actions. Table VI-2 lists the IE-only events that may assist a DHTML application (Safari implements some of these events, too). Pay special attention to the columns that show in which version of each browser the particular event was introduced. Many of these events are available only in the Windows version of IE. Not listed in Table VI-2 are the many events that apply only to Internet Explorer's data binding facilities, which allow form elements to be bound to server database sources. Bear in mind, however, that an event introduced with a limited range of elements in one browser version may have been extended to other objects in a later browser version. Chapter 3 of Dynamic HTML, Third Edition provides implementation details on all available events.
|