The purpose of this chapter is to provide a list of every event type implemented in Version 4 and later of both Netscape Navigator and Internet Explorer, as well as those specified in the W3C recommendation for the Events module of DOM Level 2. So that you can readily see whether a particular entry applies to the browser(s) you must support, a version table accompanies each term listed in the following pages. This table tells you at a glance the version of Navigator, Internet Explorer, and W3C DOM specification in which the term was first introduced.
If a listing for IE signifies Win or Mac, it means that the event is supported only for the Windows or Macintosh operating system version. Note that a large number of event types are supported only in IE for Windows, and many of those apply only to data binding applications. If you are concerned with cross-browser deployment, pay very close attention to the browser compatibility charts to find the events that work on a broad array of browser brands and versions. Chapter 6 contains many guidelines and examples for blending otherwise incompatible event mechanisms into routines that work on many browser types.
In the listings below, the "Bubbles" category indicates whether the event follows event bubbling propagation (in browsers that support event bubbling), while the "Cancelable" category means that the default action usually associated with the event (such as navigating to a new URL when clicking on an a element) can be canceled by script statements, thus averting the normal operation. The category named "Typical Targets" usually points to broad types of elements to which the event type may be applied. For more specific element support for each event type, consult Chapter 15: DOM Method Index.
DOMActivate | NN n/a IE n/a DOM 2 |
Bubbles: Yes; Cancelable: Yes |
All rendered elements that are capable of receiving focus normally (such as form controls and links), plus any other rendered element for which the tabindex attribute is assigned a value.
DOMAttrModified | NN 6 IE n/a DOM 2 |
Bubbles: Yes; Cancelable: No |
All rendered elements.
DOMCharacterDataModified | NN 6 IE n/a DOM 2 |
Bubbles: Yes; Cancelable: No |
CharacterData nodes.
DOMFocusIn, DOMFocusOut | NN n/a IE n/a DOM 2 |
Bubbles: Yes; Cancelable: No |
All rendered elements that are capable of receiving focus normally (such as form controls and links), plus any other rendered element for which the tabindex attribute is assigned a value.
DOMNodeInserted | NN 6 IE n/a DOM 2 |
Bubbles: Yes; Cancelable: No |
All rendered nodes.
DOMNodeInsertedIntoDocument | NN 6 IE n/a DOM 2 |
Bubbles: No; Cancelable: No |
All rendered nodes.
DOMNodeRemoved | NN 6 IE n/a DOM 2 |
Bubbles: Yes; Cancelable: No |
All rendered nodes.
DOMNodeRemovedFromDocument | NN 6 IE n/a DOM 2 |
Bubbles: No; Cancelable: No |
All rendered nodes.
DOMSubtreeModified | NN 6 IE n/a DOM 2 |
Bubbles: No; Cancelable: No |
All rendered nodes.
onabort | NN 3 IE 4 DOM 2 |
Bubbles: No; Cancelable: No |
The img element.
onactivate | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
All rendered elements, plus the document and window objects.
onafterprint, onbeforeprint | NN n/a IE 5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
The body and frameset elements, plus the window object.
onafterupdate | NN n/a IE 4(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
Elements that accept data input and support data binding.
onbeforeactivate | NN n/a IE 6(Win) DOM n/a |
Bubbles: Yes; Cancelable: Sometimes |
If you cancel the onbeforeactivate event, the element does not become active, nor does it receive focus, but only if the intended focus action occurs from explicit user action (clicking and tabbing). An element blocked from receiving focus causes the focus to go to another element: to the next focusable element in tabbing order (when the user tabs to the blocked element) or to the next outermost focusable parent element in the document tree (when a user clicks on the blocked element). Activating or giving focus to an element via the setActive( ) or focus( ) methods cannot be blocked by canceling this event.
All rendered elements, plus the document and window objects.
onbeforecopy | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
Rendered elements except form controls.
onbeforecut | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements.
onbeforedeactivate | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements, plus the document and window objects.
onbeforeeditfocus | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
Text form controls; rendered elements in edit mode (IE 5.5 or later); content governed by the DHTML Editing ActiveX control (see http://msdn.microsoft.com/workshop/browser/mshtml/).
onbeforepaste | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
function handleBeforePaste( ) { event.returnValue = false; } function handlePaste( ) { if (event.srcElement.className == "OK2Paste") { event.srcElement.innerText = clipboardData.getData("Text"); } }
In the above paste operation, the system clipboard never plays a role because your scripts handle the entire data transfer—all without having to go into edit mode.
All rendered elements and the document object.
onbeforeprint |
onbeforeunload | NN n/a IE 4(Win)/5(Mac) DOM n/a |
Bubbles: No; Cancelable: Yes |
In the onbeforeunload event handler, assign a string to the event.returnValue property to force IE to display a dialog box that lets the user choose whether the page should stay where it is or the navigation or window closure action that the user requested continues as expected. The string assigned to the event property becomes part of the dialog box message (other text in the message is hardwired by the browser and may not be removed or modified). The resulting action is controlled by the user's button choice in the dialog box.
The body and frameset elements, plus the window object.
onbeforeupdate | NN n/a IE 4(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
Elements that accept data input and support data binding.
onblur | NN 2 IE 3 DOM 2 |
Bubbles: No; Cancelable: No |
Avoid using the onblur event in text input fields to trigger form validation, especially if the validation routine displays an alert dialog box upon discovering an error. Interaction among the onblur and onfocus events, along with the display and hiding of an alert dialog box can put you into an infinite loop. Use onchange instead.
Although the onblur event has been supported for form controls and window objects since the early days of scriptable browsers, modern browsers can fire the event on virtually any other rendered element, provided the tabindex attribute is set for the element. Note that IE for Windows is known to omit firing the onblur event on window objects.
For all browsers, input (of type text and password), textarea, select, and window objects; for IE 5 or later and Netscape 6, add any rendered element for which the tabindex attribute is assigned a value.
onbounce | NN n/a IE 4 DOM n/a |
Bubbles: No; Cancelable: Yes |
The marquee element.
oncellchange | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
The object and applet elements.
onchange | NN 2 IE 3 DOM 2 |
Bubbles: No (IE); Yes (NN 6); Cancelable: Yes (IE); No (NN 6) |
Text-type input, textarea, and select elements.
onclick | NN 2 IE 3 DOM 2 |
Bubbles: Yes; Cancelable: Yes |
For mouse click actions, the onclick event fires only if the mouse button is pressed and released with the pointer atop the same element. In that case, the primary mouse events fire in this order: onmousedown, onmouseup, and onclick.
An event object created from a mouse event has numerous properties filled with details such as coordinates of the click and whether any modifier keys were held down during the event. Information about the button used is more reliably accessed through the onmousedown or onmouseup events. The event handler function can inspect these properties as needed.
Although the onclick event has been supported for button-oriented form controls and link objects since the early days of scriptable browsers, modern browsers can fire the event on virtually any other rendered element. Note that in Netscape 6, mouse events can fire on child text nodes of container-type elements, meaning that the event object's target property references the node, rather than the element. See Chapter 6 for details about the impact of this W3C DOM-endorsed behavior and cross-browser solutions.
For all browsers, input (of type button, radio, checkbox, reset, and submit), a, and area objects; Version 4 and later support the event for the document and window objects; for IE 4 or later and Netscape 6, add any rendered element, as well as text nodes for Netscape 6.
oncontextmenu | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements and the document object.
oncontrolselect | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements and the document object.
oncopy | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
To give users access to a Copy menu command for an otherwise uneditable element, set event.returnValue to false in the onbeforecopy event handler for the same object as the oncopy event handler. On the other hand, to prevent user copying of body content, set event.returnValue to false for the oncopy event handler. Just don't regard this tactic as a foolproof way to prevent users from copying your prized content.
Rendered elements except form controls.
oncut | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
To give users access to a Cut menu command for an otherwise uneditable element, set event.returnValue to false in the onbeforecut event handler for the same object as the oncut event handler. On the other hand, to prevent user cutting of body or form control content, set event.returnValue to false for the oncut event handler.
All rendered elements.
ondataavailable, ondatasetchanged, ondatasetcomplete | NN n/a IE 4(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
The object and applet elements; the xml element in IE 5 and later.
ondblclick | NN 4 IE 4 DOM n/a |
Bubbles: Yes; Cancelable: Yes |
Because the onclick event fires ahead of ondblclick, the associated onclick event handler (if any) should perform only innocuous actions, such as highlighting an element, much like the way operating system desktop icons operate. If an item requires a double click, that is the only event that should do something significant.
Support for this event in Navigator 4 is limited to the a element (but not on the Macintosh); IE 4 or later and Netscape 6 support the event on renderable elements and the document object.
ondeactivate | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
All rendered elements, plus the document and window objects.
ondrag, ondragend, ondragstart | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
During the drag operation, the user sees the cursor in one of its various forms, rather than seeing the actual element float around the page. As long as the user keeps the mouse button down following an initial drag action, the ondrag event keeps firing. Other drag-related events fire on other elements along the way (events such as ondragenter for an element that finds the dragged cursor in its airspace), but the ondrag event also fires at various instances.
An element with content that is dragged receives events in the following sequence: ondragstart, ondrag (perhaps many times), and ondragend. Elements in the path of the drag action receive ondragenter, ondragover, and ondragleave events, while the element at the end of the drag receives the ondrop event (which fires before the ondragend event of the dragged element). The speed of the drag action and client system speed impacts the number of event firings of all drag types. A fast drag on a slow machine may result in some events not firing.
All rendered elements and document object.
ondragdrop | NN |4| IE n/a DOM n/a |
Bubbles: No; Cancelable: No |
The window object.
ondragend |
ondragenter, ondragleave, ondragover | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
If your scripts will be performing customized actions upon the user dropping the dragged item onto a target in the document, you should prevent default actions of the ondragenter and ondragover events so that the target's ondrop event can do its job without interference from the normal system response to dragging. See the dataTransfer object in Chapter 9 for an example of drag-related event interaction.
All rendered elements and document object.
ondragstart |
ondrop | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements and document object.
onerror | NN 3 IE 4 DOM 2 |
Bubbles: No; Cancelable: Yes |
function doNothing( ) {return true;} window.onerror = doNothing;
This isn't good for debugging because you need to find errors during development. See the Error object in Chapter 9 for more details on processing errors from this event handler. Eventually, there will enough browsers deployed that use more modern exception handling.
Elements that load external content, plus the window object.
onerrorupdate | NN n/a IE 4(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
Elements that accept data input and support data binding.
onfilterchange | NN n/a IE 4(Win) DOM n/a |
Bubbles: No; Cancelable: No |
Most rendered elements.
onfinish | NN n/a IE 4 DOM n/a |
Bubbles: No; Cancelable: Yes |
The marquee element.
onfocus | NN 2 IE 3 DOM 2 |
Bubbles: No; Cancelable: No |
Although the onfocus event has been supported for form controls and window objects since the early days of scriptable browsers, modern browsers can fire the event on virtually any other rendered element, provided the tabindex attribute is set for the element. Note that IE for Windows is known to omit firing the onfocus event on window objects.
For all browsers, input (of type text and password), textarea, select, and window objects; for IE 5 or later and Netscape 6, add any rendered element for which the tabindex attribute is assigned a value.
onfocusin, onfocusout | NN n/a IE 6 DOM n/a |
Bubbles: Yes; Cancelable: No |
All rendered elements that are capable of receiving focus normally (such as form controls and links), plus any other rendered element for which the tabindex attribute is assigned a value.
onhelp | NN n/a IE 4 DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements, plus document and window objects, except in IE for Macintosh, which limits this event to the window object.
onkeydown, onkeyup | NN 4 IE 4 DOM 3 |
Bubbles: Yes; Cancelable: Yes |
All focusable rendered elements, plus document and window objects.
onkeypress | NN 4 IE 4 DOM 3 |
Bubbles: Yes; Cancelable: Yes |
All focusable rendered elements, plus the document object.
onlayoutcomplete | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
An XML LayoutRect object.
onload | NN 2 IE 3 DOM 2 |
Bubbles: No; Cancelable: No |
The event fires for a frameset element only after the onload events for all frames have fired (but the event is not bubbling from frame to frameset). Note that if the user or a script loads a new page into a frame after the frameset's initial load, the onload event does not fire again for the frameset (but it does for the frame).
Although the onload event has been supported for window objects since the early days of scriptable browsers, modern browsers fire the event on virtually any other rendered element that loads external content.
For all browsers, window objects; for Version 4 browsers or later the img element; for IE 4 or later and Netscape 6, add any rendered element capable of loading external content.
onlosecapture | NN n/a IE 5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
All rendered elements.
onmousedown, onmouseup | NN 4 IE 4 DOM 2 |
Bubbles: Yes; Cancelable: Yes |
An event object created from a mouse event has numerous properties filled with details such as coordinates of the click, the mouse button used, and whether any modifier keys were held down during the event. The event handler function can inspect these properties as needed.
Note that in Netscape 6, mouse events can fire on child text nodes of container-type elements, meaning that the event object's target property references the node, rather than the element. See Chapter 6 for details about the impact of this W3C DOM-endorsed behavior and cross-browser solutions.
All rendered elements, except in Navigator 4, where the events are limited to button-style input elements, plus a and area elements.
onmouseenter, onmouseleave | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
All rendered elements.
onmousemove | NN 4 IE 4 DOM 2 |
Bubbles: Yes; Cancelable: No |
An event object created from a mouse event has numerous properties filled with details such as coordinates of the pointer and whether any modifier keys were held down during the event. The event handler function can inspect these properties as needed.
In Navigator 4, this event type can be assigned to the window, document, and layer object, but only in the explicitly defined event capture mode. Note that in Netscape 6, mouse events can fire on child text nodes of container-type elements, meaning that the event object's target property references the node, rather than the element. See Chapter 6 for details about the impact of this W3C DOM-endorsed behavior and cross-browser solutions.
All rendered elements, except as noted above for Navigator 4.
onmouseout, onmouseover | NN 2 IE 3 DOM 2 |
Bubbles: Yes; Cancelable: Yes |
Because the onmouseout event doesn't officially fire until another element in the window fires its onmouseover event (whether you have a handler for it or not), the onmouseout event may not fire if the target element is at the edge of a window or frame, and the user whisks the pointer outside of the current frame without the first frame's body element ever receiving the onmouseover event. If you use onmouseout events to restore image swaps, the user could see a stuck image. Leave sufficient space around your swappable images to account for this behavior.
An event object created from a mouse event has numerous properties filled with details such as coordinates of the click, the mouse button used, whether any modifier keys were held down during the event, and where the incoming pointer came from or outgoing pointer has gone. The event handler function can inspect these properties as needed.
Note that in Netscape 6, mouse events can fire on child text nodes of container-type elements, meaning that the event object's target property references the node, rather than the element. See Chapter 6 for details about the impact of this W3C DOM-endorsed behavior and cross-browser solutions.
Although these events have been supported in one form or another since the early days of scriptable browsers, only modern browsers can fire the event on virtually any other rendered element. For older browsers, the events were limited to a and area elements (where a elements surrounded images to be swapped).
All rendered elements, except as noted above.
onmousewheel | NN n/a IE 6(Win) DOM n/a |
Bubbles: No; Cancelable: No |
All rendered elements and the document object.
onmove | NN |4| IE n/a DOM n/a |
Bubbles: No; Cancelable: No |
The window object.
onmove, onmoveend, onmovestart | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
<html> <head> <title>IE 5.5 (Windows) Edit Mode</title> <style type="text/css"> body {font-family:Arial, sans-serif} #myDIV {position:absolute; height:100px; width:300px;} .regular {border:5px black solid; padding:5px; background-color:lightgreen} .moving {border:5px maroon dashed; padding:5px; background-color:lightyellow} .chosen {border:5px maroon solid; padding:5px; background-color:lightyellow} </style> <script type="text/javascript"> // built-in dragging support document.execCommand("2D-position",false,true); // preserve content between modes var oldHTML = ""; // engage static edit environment function editOn( ) { var elem = event.srcElement; elem.className = "chosen"; } // engage special edit-move environment function moveOn( ) { var elem = event.srcElement; oldHTML = elem.innerHTML; elem.className = "moving"; } // display coordinates during drag function trackMove( ) { var elem = event.srcElement; elem.innerHTML = "Element is now at: " + elem.offsetLeft + ", " + elem.offsetTop; } // turn off special edit-move environment function moveOff( ) { var elem = event.srcElement; elem.innerHTML = oldHTML; elem.className = "chosen"; } // restore original environment (wrapper gets onfocusout) function editOff( ) { var elem = event.srcElement; if (elem.id == "wrapper") { elem.firstChild.className = "regular"; } } // initialize event handlers function init( ) { document.body.oncontrolselect = editOn; document.body.onmovestart = moveOn; document.body.onmove = trackMove; document.body.onmoveend = moveOff; document.body.onfocusout = editOff; } </script> </head> <body onload="init( );"> <div id="wrapper" contenteditable="true"> <div id="myDIV" class="regular"> This is a positioned element with some text in it. </div> </div> </body> </html>
An XML LayoutRect object.
onpaste | NN n/a IE 5(Win) DOM n/a |
Bubbles: Yes; Cancelable: Yes |
To give users access to a Paste menu command for an otherwise uneditable element, set event.returnValue to false in the onbeforepaste event handler for the same object as the onpaste event handler. On the other hand, to prevent user pasting system clipboard content, set event.returnValue to false for the onpaste event handler.
All rendered elements.
onpropertychange | NN n/a IE 5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
All rendered elements, plus the document object.
onreadystatechange | NN n/a IE 4 DOM n/a |
Bubbles: No; Cancelable: No |
Elements that load external content.
onreset | NN 3 IE 4 DOM 2 |
Bubbles: No; Cancelable: Yes |
The form element.
onresize | NN 4 IE 4 DOM 2 |
Bubbles: Yes; Cancelable: No |
For IE, elements that have dimensions associated with them, plus the window and document objects; for Navigator, the window and document objects.
onresizeend, onresizestart | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
All rendered elements.
onrowenter, onrowexit, onrowsdelete, onrowsinserted | NN n/a IE 4(Win) DOM n/a |
Bubbles: Yes; Cancelable: No |
The object and applet elements; the xml element in IE 5 and later.
onscroll | NN n/a IE 4 DOM 2 |
Bubbles: No; Cancelable: No |
All rendered elements that can have scrollbars by default (such as textarea and window objects), plus any element that has its overflow style sheet attribute set to scroll.
onselect | NN 2 IE 3 DOM 2 |
Bubbles: No (IE); Yes (NN 6); Cancelable: Yes |
Text-type input and textarea elements for all browsers; body element for IE 4 or later for Windows.
onselectionchange | NN n/a IE 5.5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
The document object.
onselectstart | NN n/a IE 4 DOM n/a |
Bubbles: Yes; Cancelable: Yes |
All rendered elements.
onstart | NN n/a IE 4 DOM n/a |
Bubbles: No; Cancelable: No |
The marquee element.
onstop | NN n/a IE 5(Win) DOM n/a |
Bubbles: No; Cancelable: No |
The document object.
onsubmit | NN 2 IE 3 DOM 2 |
Bubbles: No (IE); Yes (NN 6); Cancelable: Yes |
The form element.
onunload | NN 2 IE 3 DOM 2 |
Bubbles: No; Cancelable: No |
The body and frameset elements, plus the window object.
Copyright © 2003 O'Reilly & Associates. All rights reserved.