eventNN 4 IE 4 DOM 2

The event object contains information about a user- or system-generated event. But there are three different kinds of event objects, one for each of the event object models deployed in browsers: IE for Windows, Navigator 4, and Netscape 6 (from the W3C DOM). IE 5 for Macintosh implements a hybrid of the IE for Windows and Netscape 6 version. See Chapter 6 for examples of processing events in a cross-browser environment. It is rare that an event object property applies to more than one of the event models, so pay special attention to the browser compatibility listings for each of the following properties.

 

The Netscape 6 event object is more complex in some ways due to the object-oriented nature of the underlying W3C DOM Event object structure. Rather than being an all-encompassing object (as the IE event object is), the Netscape 6 event object exposes different sets of properties and methods depending on the classification of event. All event classes share the properties and methods of the W3C DOM root Event object. But actual event object instances belong to one of the Event object's subclasses (and sometimes, sub-subclasses). These subclasses are known as UIEvent (so-called user interface events such as DOMFocusIn), MouseEvent (including the well-known mouse events), MutationEvent (events that signal a scripted change to the node structure of the document), and, coming in DOM Level 3, TextEvent (keyboard-related events). Netscape 6 implements its own, temporary keyboard events classification under the name KeyEvent, which is a subclass of UIEvent, although it borrows some MouseEvent properties for scripting convenience.

 

By and large, this functional division of objects won't impact your Netscape 6 event processing because an event listener function for a particular kind of event will be looking for properties associated with that event. The event class is of little concern. Still, it is instructive to see the way event object properties and methods cascade through this object-oriented structure. The following table illustrates the distribution of properties among Netscape 6 and W3C DOM event classes.

 

And the following table illustrates the distribution of methods among Netscape 6 and W3C DOM event classes.

 

The event object in Netscape 6 also implements the properties of the Navigator 4 static Event object, and it inherits an enormous list of W3C DOM TextEvent object constants that represent nonalphanumeric keyboard key codes (which have constant names like eventObject.DOM_VK_PAGE_UP). These keyboard constants are defined in the forthcoming W3C DOM Level 3 events module, but are already implemented in Netscape 6 (although the values don't exactly line up yet). A list of properties for the Navigator 4 static Event object appears in the Event object discussion following the current foray through an instance of an event.

 

As described in detail throughout Chapter 6, you must use different script techniques to obtain a reference to an event object in the IE and Navigator event models. Once you have that reference, you are well on your way to equalizing event processing across browsers. The example fragments that follow assume that previous script statements have obtained a reference to the browser-specific event object (usually shown in the example as stored in a variable called evt).

 
EventUIEventMouseEventKeyEventImplemented in Netscape 6 for additional functionality or in lieu of unfinished DOM Level 3 keyboard event model. Borrows some MouseEvent properties for scripting convenience.TextEventProposed for DOM Level 3, but not implemented in Netscape 6.MutationEvent
Event properties
bubbles
cancelable
cancelBubble IE property implemented in Netscape 6 for cross-browser convenience.
currentTarget
eventPhase
originalTarget8
target
timeStamp
type
UIEvent properties
detail
view
MouseEvent properties
altKey
button
clientX
clientY
ctrlKey
metaKey
relatedTarget
screenX
screenY
shiftKey
KeyEvent properties
charCode8
isChar8
keyCode8
rangeOffset8
rangeParent8
TextEvent properties
keyVal9
numPad9
outputString9
virtKeyVal9
visibleOutputGenerated9
MutationEvent properties
attrChange
attrName
newValue
prevValue
relatedNode
 
EventUIEventMouseEventKeyEventImplemented in Netscape 6 for additional functionality or in lieu of unfinished DOM Level 3 keyboard event model. Borrows some MouseEvent properties for scripting convenience.TextEventProposed for DOM Level 3, but not implemented in Netscape 6.MutationEvent
Event methods
initEvent( )
getPreventDefault( )11
preventDefault( )
stopPropagation( )
UIEvent methods
initUIEvent( )
MouseEvent methods
initMouseEvent( )
KeyEvent methods
initKeyEvent( )
TextEvent methods
checkModifier( )12
initModifier( )12
initTextEvent( )12
MutationEvent methods
initMutationEvent( )
 
Object Model Reference
 
  • eventObj
  • [window.]event
 
Object-Specific Properties
 
altKeyaltLeftattrChangeattrName
behaviorCookiebehaviorPartbookmarksboundElements
bubblesbuttoncancelablecancelBubble
charCodeclientXclientYcontentOverflow
ctrlKeyctrlLeftcurrentTargetdata
dataFlddataTransferdetaileventPhase
fromElementisCharkeyCodelayerX
layerYmetaKeymodifiersnewValue
nextPageoffsetXoffsetYoriginalTarget
pageXpageYprevValuepropertyName
qualifierrangeOffsetrangeParentreason
recordsetrelatedNoderelatedTargetrepeat
returnValuescreenXscreenYshiftKey
shiftLeftsrcElementsrcFiltersrcUrn
targettimeStamptoElementtype
viewwheelDeltawhichx
y
 
Object-Specific Methods
 
getPreventDefault( )initEvent( )initKeyEvent( )initMouseEvent( )
initMutationEvent( )initUIEvent( )preventDefault( )stopPropagation( )
 
Object-Specific Event Handler Properties

None.

altKeyNN 6 IE 4 DOM 2

Read-only

Returns true if the left or right Alt key is down at the time the event fired.

 
Example
 
if (evt.altKey) {
    //handle case of Alt key down
}
 
Value

Boolean value: true | false.

 
Default

false

altLeftNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns true if the left Alt key is down at the time the event fired.

 
Example
 
if (evt.altLeft) {
    //handle case of left Alt key down
}
 
Value

Boolean value: true | false.

 
Default

false

attrChangeNN 6 IE n/a DOM 2

Read-only

Returns an integer code corresponding to the type of change made to an Attr node as the result of a DOMAttrModified event type of W3C DOM mutation event. Every mutation event object has three constants that also correspond to the integer values, which you can use to make more verbose, but easier-to-read script comparisons for DOMAttrModified event processing. The values and constants are shown in the following table.

 
ValueConstantDescription
1evtObj.MODIFICATIONChanged value of existing Attr node
2evtObj.ADDITIONThe Attr node was added to the document tree
3evtObj.REMOVALThe Attr node was removed from the document tree
 
Example
 
if (evt.attrChange == evt.MODIFICATION) {
    // do post-processing of attribute value change
}
 
Value

Integer value: 1 | 2 | 3.

 
Default

None.

attrNameNN 6 IE n/a DOM 2

Read-only

Returns a string version of the name of an Attr node affected by a DOMAttrModified event type of W3C DOM mutation event.

 
Example
 
var changedAttr = evt.attrName;
 
Value

String value.

 
Default

Empty string.

behaviorCookie, behaviorPart, bookmarks, boundElementsNN n/a IE 6(Win) DOM n/a

Read-only

These properties are returned by the event object in IE 6 for Windows (with values 0, 0, null, and the empty array, respectively), but Microsoft does not document them. Perhaps they will be supported and implemented in a future version.

bubblesNN 6 IE n/a DOM 2

Read-only

Returns Boolean true if the default behavior of the event is to allow the event to bubble through the element hierarchy.

 
Example
 
if (evt.bubbles) {
    // handle case of the event bubbling
}
 
Value

Boolean value: true | false.

 
Default

Event type-specific.

buttonNN 6 IE 4 DOM 2

Read-only

Inidicates which mouse button was pressed to trigger the mouse event. Be aware that the typical Macintosh has only a one-button mouse. Also, if you want to intercept the right-click context menu in IE/Windows, use the oncontextmenu event handler.

 

A significant discrepancy exists among DOM specifications and implementations with respect to the numbers returned for this property. The W3C DOM, as implemented in Netscape 6, specifies a value of zero to indicate the left (primary) button. IE for Windows supports additional values for mouse button combinations.

 
Example
 
if (evt.button == 2) {
    // handle event for right button
}
 
Value

Integer value according to the following table.

 
Button(s)IENN 6W3C DOM
No button0nullnull
Left (primary)100
Middle411
Right222
Left + Right3n/an/a
Left + Middle5n/an/a
Right + Middle6n/an/a
Left + Middle + Right7n/an/a
 
Default

0

cancelableNN 6 IE n/a DOM 2

Read-only

Returns Boolean true if the event is of the type that can have its default behavior on the target element cancelled via the preventDefault( ) method.

 
Example
 
if (evt.cancelable ) {
    evt.preventDefault( );
}
 
Value

Boolean: true | false.

 
Default

Event type-specific.

cancelBubbleNN 6 IE 4 DOM n/a

Read/Write

Specifies whether the event should propagate (bubble) up the element container hierarchy. You usually only need to set this property to true to override the default behavior and prevent the event from going any further. Netscape 6 implements this IE property for convenience. The W3C DOM equivalent is the stopPropagation( ) method of the event object.

 
Example
 
evt.cancelBubble = true;
 
Value

Boolean: true | false.

 
Default

false

charCodeNN 6 IE n/a DOM n/a

Read-only

Returns an integer corresponding to the Unicode value of the character generated by the key that fired the event. The character code is different from the key code, as the character code distinguishes between upper- and lowercase letters (for example, 97 for "a" and 65 for "A"), whereas the keyCode value is the same for that key, regardless of the character created from it. This property generally contains a value only for onkeypress events; the value is zero for onkeydown and onkeyup events. For the IE equivalent, see the keyCode property.

 

When the keyboard events module is completed for W3C DOM Level 3, this property will probably have a different name.

 
Example
 
if (evt.charCode > 96 && evt.charCode < 123) {
    evt.target.value += String.fromCharCode(evt.charCode - 32);
    evt.preventDefault( );
}
 
Value

Integer.

 
Default

Event-specific.

clientX, clientYNN 6 IE 4 DOM 2

Read-only

Indicate the horizontal (x) and vertical (y) coordinate of the mouse at the moment the current event fired. These coordinates are relative to the viewable document area of the browser window or frame. To convert these coordinates to the document's in IE, be sure to add the body element's scroll values (or html element's scroll values in IE 6 standards-compatible mode). For Netscape 6, the pageX and pageY properties provide coordinates in the document's space.

 
Example
 
if ((evt.clientX >= 10 && evt.clientX <= 20) &&
(evt.clientY >= 50 && evt.clientY <= 100)) {
    // process code for click in hot zone bounded by 10,50 and 20,100
}
 
Value

Integer of pixel values.

 
Default

None.

contentOverflowNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns Boolean true if as-yet unrendered content requires a new layout rectangle to handle the overflow content. The property applies only to the onlayoutcomplete event if you deploy custom print or print preview templates. For more on the C++ programming required for such templates, visit http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/printpreview/reference/reference.asp.

 
Value

Boolean: true | false.

 
Default

false

ctrlKeyNN 6 IE 4 DOM 2

Read-only

Returns true if the left or right Control key was pressed at the instant the event fired. See Chapter 6 for testing for this key in cross-browser event handling code.

 
Example
 
if (evt.ctrlKey) {
    // process for Control key being down
}
 
Value

Boolean value: true | false.

 
Default

false

ctrlLeftNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns true if the left Control key was pressed at the instant the event fired.

 
Example
 
if (evt.ctrlLeft) {
    // process for left Control key being down
}
 
Value

Boolean value: true | false.

 
Default

false

currentTargetNN 6 IE n/a DOM 2

Read-only

Returns a reference to the node whose event listener is currently processing the event. Allows a function to know whether it is invoked from the actual target node or a different node during event propagation.

 
Example
 
if (evt.currentTarget.nodeType == 1) {
    // process at element level for possible text node target
}
 
Value

Reference to a node in event propagation hierarchy.

 
Default

Reference to event target.

dataNN |4| IE n/a DOM n/a

Read-only

Provides accessory data associated with the Navigator 4-only dragdrop event. The data property returns the URL of the item being dropped onto the window or frame.

 
Example
 
var srcDoc = evtObj.data;
 
Value

String.

 
Default

None.

dataFldNN n/a IE 5(Win) DOM n/a

Read/Write

Used with IE data binding, the dataFld property holds the name of the data source object's field associated with the column of the HTML table. This property contains a value after an oncellchange event in a table generated via data binding.

 
Value

String.

 
Default

Empty string.

dataTransferNN n/a IE 5(Win) DOM n/a

Read-only

Returns a reference to the dataTransfer object to facilitate moving customized data between source and destination elements during a drag-and-drop operation. See the dataTransfer object for details of its usage.

 
Value

Reference to dataTransfer object.

 
Default

None.

detailNN 6 IE n/a DOM 2

Read-only

Returns an integer conveying event type-specific additional information. For mouse button events, the number indicates how many times the user clicked the mouse on the same coordinate position as the previous click without moving the cursor away from the location. Moving the cursor resets the counter to zero in preparation for the next press and release of the mouse button. For a DOMActivate event type, the detail property returns 1 for activation by a simple user action (click or tab), and 2 for a more complex action (a double-click).

 
Example
 
if (evt.type == "click" && evt.detail > 5) {
    alert("Relax, dude!");
}
 
Value

Integer.

 
Default

Event-type specific.

eventPhaseNN 6 IE n/a DOM 2

Read-only

Returns an integer conveying whether the event listener is processing the event while in the capture phase, at the event target, or in the bubbling phase. W3C DOM event objects also implement plain-language constants corresponding to the three values.

 
Example
 
if (evt.eventPhase == evt.AT_TARGET) {
    // process event listener from the event target
}
 
Value

Integer value from the following table.

 
ValueConstant
1eventObjectReference.CAPTURING_PHASE
2eventObjectReference.AT_TARGET
3eventObjectReference.BUBBLING_PHASE
 
Default

2

fromElementNN n/a IE 4 DOM n/a

Read-only

Returns a reference to the object where the cursor was located just prior to the onMouseOver or onMouseOut event.

 
Example
 
if (evt.fromElement.id == "lowerLevel") {
    ...
}
 
Value

Element object reference.

 
Default

None.

isCharNN 6 IE n/a DOM n/a

Read-only

Returns true if the keyboard event is from a character key. In practice Netscape 6 returns true for all keys, including function keys. Use onkeydown or onkeyup event handlers to process noncharacter keys.

 
Value

Boolean value: true | false.

 
Default

true

keyCodeNN 6 IE 4 DOM n/a

Read/Write

Slightly different characteristics for IE and Netscape 6, but the two browser classes treat the keyCode property the same way for onkeydown and onkeyup events. For these events, the keyCode property returns the code associated with the keyboard key, irrespective of the character that might be generated by that key. On a typical Latin character set keyboard, the A key generates the code 65. Modifier keys generate their own events and codes as they are pressed and released.

 

For the onkeypress event, only IE returns a significant value, corresponding to the Unicode value of the actual character displayed in a text box by typing the character (e.g., 65 for "A" and 97 for "a"). The equivalent property in Netscape 6 for the onkeypress event is charCode. See Chapter 6 about processing keyboard events.

 
Example
 
if (evt.keyCode == 65) {
    ...
}
 
Value

Integer.

 
Default

None.

layerX, layerYNN 4 IE n/a DOM n/a

Read-only

Provide the horizontal (x) and vertical (y) coordinate of the mouse at the moment the current event fired. These coordinates are relative to the containing layer. If no layers or positionable elements have been defined, the default layer of the base document is used as a reference point, thus equivalent to the pageX and pageY properties. In Netscape 6 and later, these properties are measured relative to the element's own rectangular space for text and password input elements, textarea elements, and select elements.

 
Example
 
if ((evt.layerX >= 10 && evt.layerX <= 20) &&
(evt.layerY >= 50 && evt.layerY <= 100)) {
    // process code for click in hot zone bounded by 10,50 and 20,100
}
 
Value

Integer of pixel values.

 
Default

None

metaKeyNN 6 IE n/a DOM n/a

Read-only

Returns true if the keyboard's Meta key (Command key on the Macintosh keyboard) was pressed at the instant the event fired.

 
Example
 
if (evt.metaKey) {
    // process for meta key being down
}
 
Value

Boolean value: true | false.

 
Default

false

modifiersNN |4| IE n/a DOM n/a

Read-only

Provides an integer that represents the keyboard modifier key(s) being held down at the time the Navigator 4-only event fired. You can use the & operator with a series of static Event object constants to find out whether a particular modifier key was pressed. See Chapter 6.

 
Example
 
var altKeyPressed = evt.modifiers & Event.ALT_MASK;
 
Value

Integer.

 
Default

0

newValue, prevValueNN 6 IE n/a DOM 2

Read-only

Return a string with the new and previous values (respectively) of data associated with DOMAttrModified and DOMCharacterDataModified event types of the W3C DOM mutation events class. This information could be useful for creating an undo buffer for changes to an element's attribute or the content of a CharacterData node.

 
Example
 
undoAttrBuffer = {attrNode:evt.relatedNode, oldVal:evt.prevValue};
 
Value

String value.

 
Default

Empty string.

nextPageNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns a string indicating whether the next page of a custom print template will appear on a left- or right-facing page. For more on the C++ programming required for templates, visit http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/printpreview/reference/reference.asp.

 
Value

String constant: left | right | (empty string).

 
Default

Empty string.

offsetX, offsetYNN n/a IE 4 DOM n/a

Read-only

Provide the left and top coordinates of the mouse pointer relative to the containing element (exclusive of padding, borders, or margins) when the event fired. You can determine the containing element via the offsetParent property. See the Section 9.2 at the beginning of this chapter for information on offset measurement anomalies in Internet Explorer.

 
Example
 
if (evt.offsetX <= 20 && evt.offsetY <=40) {
    ...
}
 
Value

Integer pixel count.

 
Default

None.

originalTargetNN 6 IE n/a DOM n/a

Read-only

Returns a reference to a node that Netscape 6 internally treats as the genuine first target of the event. By and large, this information isn't helpful to DHTML scripting, because it dives into the internal construction of certain elements (e.g., an input element of type text has a div element nested inside of it, but the DOM node tree does not see the div element as a child node of the input element). For many events and event targets, the target and originalTarget properties reference the identical node.

 
Value

Node object reference

 
Default

Element-specific.

pageX, pageYNN 4 IE n/a DOM n/a

Read-only

Provide the left and top coordinates of the element's content relative to the top-left corner of the page area when the event fired. The measurements ignore any scrolling of the page.

 
Example
 
if (evt.pageX <= 20 && evt.pageY <=40) {
    ...
}
 
Value

Integer pixel count.

 
Default

None.

prevValue

See newValue.

propertyNameNN n/a IE 5(Win) DOM n/a

Read/Write

Returns a string containing the name of the object property that changed during an onpropertychange event. For other event types, the value is an empty string. If the changed property is a property of a property (e.g., a property of an element's style property), the returned value shows the "dot" version, such as style.color.

 
Example
 
if (evt.propertyName.indexOf("style") == 0) {
    // perform further processing on a changed style
}
 
Value

String property name.

 
Default

Empty string.

qualifierNN n/a IE 5(Win) DOM n/a

Read/Write

For use with IE data binding events (such as ondatasetcomplete). Returns a string value signifying a data source member, which may then be used as a parameter to access a data source's named recordset. Consult the Microsoft documentation for the Data Source Object you use to see if it provides qualifier data.

 
Value

String.

 
Default

Empty string.

rangeOffsetNN 6 IE n/a DOM n/a

Read-only

Returns an integer of the character offset within a node that the Netscape 6 DOM considers a potential Range end point. The reference to the node is found in the associated rangeParent property of the event object. These two values can be passed as parameters to W3C DOM Range object methods for setting a start or end point. Thus, a mousedown event listener could establish the start point of a range, while a mouseup event listener function could set the end pointboth functions feeding rangeParent and rangeOffset values to the Range object methods.

 
Example
 
var rng;
function processMouseDown(evt) {
    rng = document.createRange( );
    rng.setStart(evt.rangeParent, evt.rangeOffset);
}
 
Value

Integer.

 
Default

0

rangeParentNN 6 IE n/a DOM n/a

Read-only

Returns a reference to a document tree node that would be a suitable start or end point for a W3C text range. Use in concert with the rangeOffset property.

 
Example
 
function processMouseUp(evt) {
    rng.setEnd(evt.rangeParent, evt.rangeOffset);
}
 
Value

Reference to a node.

 
Default

None.

reasonNN n/a IE 4 DOM n/a

Read/Write

Returns a code associated with an ondatasetcomplete event signifying whether the IE data binding data transfer was successful or, if incomplete, whether the transfer stopped due to an error or a stoppage by the client or user. This property must be examined in an event handler for the ondatasetcomplete event. In IE 4, the property is read-only. Although IE 5/Mac includes this property of the event object, it does not implement the associated event.

 
Example
 
if (evt.reason == 2) {
    alert("An error occurred during the most recent update.");
}
 
Value

One of three possible integer values:

 
0

Transfer was successful

1

Transfer aborted

2

An error halted the transfer

 
Default

None.

recordsetNN n/a IE 5(Win) DOM n/a

Read/Write

Returns a reference to an IE data binding recordset object associated with a data-related event.

 
Value

Object reference.

 
Default

None.

relatedNodeNN 6 IE n/a DOM 2

Read-only

Returns a reference to a node that is affected by the action that triggers some W3C DOM mutation events. This provides a more direct route to a node that is impacted by the event, according to the following table.

 

For other mutation event types, the property returns null; for other event classes, the property returns undefined.

 
Mutation event typeeventObj.relatedNode reference
DOMNodeInsertedParent node of inserted node
DOMNodeRemovedOriginal parent node of removed node
DOMAttrModifiedAttr node
 
Example
 
var newParent = evt.relatedNode;
 
Value

Reference to a node, null, or undefined.

 
Default

None.

relatedTargetNN 6 IE n/a DOM 2

Read-only

Returns a reference to a rendered node in the document tree that was the previous or next target for events, depending on the event type. For a mouseover event type, the relatedTarget property refers to the node from which the cursor arrived; for a mouseout event, the relatedTarget property refers to the node to which the cursor departed. The corresponding IE functionality is in the fromElement and toElement properties of the IE event object.

 
Example
 
var beenThere = evt.relatedTarget;
 
Value

Reference to a node.

 
Default

None.

repeatNN n/a IE 5(Win) DOM n/a

Read/Write

For an onkeydown event only, returns Boolean true if the key has been down long enough to enter auto-repeat mode. You can prevent auto-repeated keys from being entered into a field with the following example.

 
Example
 
function handleKeyDown( ) {
    if (evt.repeat) {
        evt.returnValue = false;
    }
}
 
Value

Boolean value: true | false.

 
Default

false

returnValueNN n/a IE 4 DOM n/a

Read/Write

Provides the value to be returned to the event's source element to allow or prohibit the element's default action connected with the event. If you set event.returnValue to false, the element does not carry out its normal operation, such as navigating to a link or submitting the form. This property does not influence an actual value you may wish to return from an event handler function.

 
Example
 
evt.returnValue = false;
 
Value

Boolean value: true | false.

 
Default

true

screenX, screenYNN 4 IE 4 DOM 2

Read-only

Provide the horizontal and vertical pixel coordinate points where the cursor was located on the video screen when the event occurred. The top-left corner of the screen is point 0,0. There is no particular coordination with the browser window or document, unless you have positioned the window and know where the active window area is in relation to the screen.

 
Example
 
if (evt.screenX < 5 || evt.screenY < 5) {
    alert("You\'re too close to the edge!");
}
 
Value

Any positive integer or zero.

 
Default

0

shiftKeyNN 6 IE 4 DOM 2

Read-only

Returns true if the left or right Shift key was pressed at the instant the event fired.

 
Example
 
if (evt.shiftKey) {
    // process for Shift key being down
}
 
Value

Boolean value: true | false.

 
Default

false

shiftLeftNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns true if the left Shift key was pressed at the instant the event fired.

 
Example
 
if (evt.shiftLeft) {
    // process for left Shift key being down
}
 
Value

Boolean value: true | false.

 
Default

false

srcElementNN n/a IE 4 DOM n/a

Read-only

Refers to the element object that initially received the current event. This property is convenient in switch constructions for an event handler function that handles the same event type for a number of different elements. The corresponding property for Netscape 6 is target.

 
Example
 
switch (evt.srcElement.id) {
    case "myDIV":
        ...
    ...
}
 
Value

Element object reference.

 
Default

None.

srcFilterNN n/a IE 4(Win) DOM n/a

Read-only

Refers to the filter object that fired an onfilterchange event.

 
Value

Filter object reference.

 
Default

None.

srcUrnNN n/a IE 5(Win) DOM n/a

Read-only

String of the URN of an attached behavior that fired an event.

 
Value

String.

 
Default

null

targetNN 4 IE n/a DOM 2

Read-only

Refers to the node object that is the intended destination of the current event. Unlike the corresponding IE srcElement property, the target property in Netscape 6 can refer to a text node, even if the event handler is defined for the element that surrounds the text node. Your event processing for such a scenario must take the nodeType into account to equalize the reference to the surrounding element for both IE and Navigator. See Chapter 6 for examples of cross-browser event handling code.

 
Example
 
var elem = (evt.target) ? evt.target : evt.srcElement;
 
Value

Node object reference.

 
Default

None.

timeStampNN 6 IE n/a DOM 2

Read-only

Provides an integer signifying a milliseconds value you can use as a relative indicator of when an event occurred. Although the W3C DOM suggests the value should be the time since 1 January 1970 (the Java and JavaScript epoch), you cannot rely on that value. But you can compare the timeStamp property value for two events to derive the elapsed time between events.

 
Example
 
var clickTime = evt.timeStamp;
 
Value

Integer.

 
Default

Current timestamp.

toElementNN n/a IE 4 DOM n/a

Read-only

Returns a reference to the element object to which the cursor has moved that triggered the onmouseout event.

 
Example
 
if (evt.toElement.id == "upperLevel") {
    ...
}
 
Value

Element object reference.

 
Default

None.

typeNN 4 IE 4 DOM 2

Read-only

Indicates the type of the current event (without the "on" prefix). Values are all lowercase.

 
Example
 
if (evt.type == "change") {
    ...
}
 
Value

Any event name (without the "on" prefix) as a string.

 
Default

None.

viewNN 6 IE n/a DOM 2

Read-only

Returns a reference to the W3C DOM view (i.e., the window or frame object in Netscape's implementation) in which the event occurred.

 
Example
 
var whichWin = evt.view;
 
Value

Reference to a window type of object.

 
Default

Current window.

wheelDeltaNN n/a IE 5.5(Win) DOM n/a

Read-only

Returns an integer indicating which direction the user rolled the mouse wheel (for a mouse equipped with a wheel) during an onmousewheel event. A positive value means the user rolled the wheel toward the screen; a negative value means the opposite direction.

 
Example
 
if (evt.wheelDelta > 0) {
    ...
}
 
Value

Integer, typically 120 or -120.

 
Default

None.

whichNN 4 IE n/a DOM n/a

Read-only

Returns a value relevant to the type of event. For mouse events, the property value is an integer indicating which mouse button was used (1 is the left button; 3 is the right button). For keyboard events, the property value is an integer of the keyboard character ASCII code. This property survives in Netscape 6 as a carryover from the Navigator 4 event model. Use the button, charCode, and keyCode properties if you no longer need to support Navigator 4.

 
Example
 
if (evt.which == 65) {
    ...
}
 
Value

Integer.

 
Default

None.

x, yNN n/a IE 4 DOM n/a

Read-only

Return the horizontal and vertical pixel coordinates of the mouse pointer at the time the event occurred. For all but relative-positioned elements, the coordinate system is the body element (or html element in IE 6 standards-compatible mode). If the event occurs inside a relative-positioned element's rectangle, the coordinate system is limited to that element's space (the element's top left corner being 0,0). A value of -1 is returned if the pointer was outside of the document area of the browser window.

 
Example
 
if (evt.x < 20 && evt.y < 30) {
    ...
}
 
Value

Integer.

 
Default

None.

getPreventDefault( )NN 6 IE n/a DOM n/a

Returns Boolean true if the preventDefault( ) method has been invoked for the current event object. Essentially lets a script inquire about the prevent-default state. This property is a Netscape 6 extension to the W3C DOM events module.

 
Parameters

None.

 
Returned Value

Boolean value: true | false.

initEvent( )NN 6 IE n/a DOM 2

initEvent("eventType", bubblesFlag, cancelableFlag)

Indicates the minimum initialization required on an event object that is generated by document.createEvent( ). After a script-generated event is initialized, it may be used as a parameter to a node's dispatchEvent( ) method.

 
Parameters
 
  • String identifier for the event's type, such as click, mousedown, keypress, DOMAttrModified, and so on.
  • Boolean value (true | false) determining whether the event's default propagation behavior is to bubble.
  • Boolean value (true | false) determining whether the event's default action may be prevented via the preventDefault( ) method.
 
Returned Value

None.

initKeyEvent( )NN 6 IE n/a DOM n/a

initKeyEvent("eventType", bubblesFlag, cancelableFlag, view, ctrlKeyFlag, altKeyFlag, shiftKeyFlag, metaKeyFlag, keyCode, charCode)

Initializes a newly created event object with a complete set of property values associated with any keyboard event. This method's name and parameter makeup may change for the formal DOM Level 3 events module, where keyboard events (tentatively called text events) will be published. All parameters must be present, and must be set to default values (such as false for Boolean key flags or zero for integer code numbers) if the values are not significant for the event type.

 
Parameters
 
  • String identifier for the event's type: keydown, keypress, keyup.
  • Boolean value (true | false) determining whether the event's default propagation behavior is to bubble.
  • Boolean value (true | false) determining whether the event's default action may be prevented via the preventDefault( ) method.
  • Reference to the window or frame object in which the dynamically-generated event is supposed to have occurred.
  • Boolean value (true | false) of the Control key state for this event.
  • Boolean value (true | false) of the Alt key state for this event.
  • Boolean value (true | false) of the Shift key state for this event.
  • Boolean value (true | false) of the Meta key(e.g., Macintosh Command key) state for this event.
  • Integer key code for this event.
  • Integer character code for this event.
 
Returned Value

None.

initMouseEvent( )NN 6 IE n/a DOM 2

initMouseEvent("eventType", bubblesFlag, cancelableFlag, view, detailVal, screenX, screenY, clientX, clientY, ctrlKeyFlag, altKeyFlag, shiftKeyFlag, metaKeyFlag, buttonCode, relatedTargetNodeRef)

Initializes a newly created event object with a complete set of property values associated with any mouse event. All parameters must be present, and must be set to default values (such as false for Boolean key flags, zero for integer values, or null for a node reference) if the values are not significant for the event type.

 
Parameters
 
  • String identifier for the event's type, such as click, mousedown, mousemove, mouseout, mouseover, mouseup.
  • Boolean value (true | false) that determines whether the event's default propagation behavior is to bubble.
  • Boolean value (true | false) that determines whether the event's default action may be prevented via the preventDefault( ) method.
  • Reference to the window or frame object in which the dynamically-generated event is supposed to have occurred.
  • Integer code for detail data associated with the event.
  • Integer for horizontal screen coordinate.
  • Integer for vertical screen coordinate.
  • Integer for horizontal browser window coordinate.
  • Integer for vertical browser window coordinate.
  • Boolean value (true | false) of the Control key state for this event.
  • Boolean value (true | false) of the Alt key state for this event.
  • Boolean value (true | false) of the Shift key state for this event.
  • Boolean value (true | false) of the Meta key(e.g., Macintosh Command key) state for this event.
  • Integer button code for this event.
  • Reference to node receiving the previous or next mouse event.
 
Returned Value

None.

initMutationEvent( )NN 6 IE n/a DOM 2

initMutationEvent("eventType", bubblesFlag, cancelableFlag, relatedNodeRef, prevValue, newValue, attrName, attrChangeCode)

Initializes a newly created event object with a complete set of property values associated with any mutation event. All parameters must be present, and must be set to default values (such as false for Boolean key flags or zero for integer code numbers) if the values are not significant for the event type.

 
Parameters
 
  • String identifier for the event's type: DOMAttrModified, DOMCharacterDataModified, DOMNodeInserted, DOMNodeInsertedIntoDocument, DOMNodeRemoved, DOMNodeRemovedFrom-Document, DOMSubtreeModified.
  • Boolean value (true | false) determining whether the event's default propagation behavior is to bubble.
  • Boolean value (true | false) determining whether the event's default action may be prevented via the preventDefault( ) method.
  • Reference to a node associated with the event. Applicable only to DOMNodeInserted, DOMNodeRemoved, DOMAttrModified event types.
  • String of previous value for an Attr or CharacterData node. Applicable only to DOMAttrModified and DOMCharacterDataModified event types.
  • String of new value for an Attr or CharacterData node. Applicable only to DOMAttrModified and DOMCharacterDataModified event types.
  • String of the name of an Attr node. Applicable only to the DOMAttrModified event type.
  • Integer for the code corresponding to the type of change the event simulates. Applicable only to the DOMAttrModified event type.
 
Returned Value

None.

initUIEvent( )NN 6 IE n/a DOM 2

initUIEvent("eventType", bubblesFlag, cancelableFlag, view, detailVal)

Initializes a newly created event object with a complete set of property values associated with any UI event. All parameters must be present, and must be set to default values (such as false for Boolean key flags or zero for integer values) if the values are not significant for the event type.

 
Parameters
 
  • String identifier for the event's type, such as DOMFocusIn, DOMFocusOut, DOMActivate.
  • Boolean value (true | false) determining whether the event's default propagation behavior is to bubble.
  • Boolean value (true | false) determining whether the event's default action may be prevented via the preventDefault( ) method.
  • Reference to the window or frame object in which the dynamically generated event is supposed to have occurred.
  • Integer code for detail data associated with the event.
 
Returned Value

None.

preventDefault( )NN 6 IE n/a DOM 2

Instructs the current event to bypass the normal operation it performs on the node. Once set, the mode cannot be undone for the current event. The following Netscape 6 event listener function for an keypress event allows only numbers to be entered into a text field:

function numsOnly(evt) {
    if (evt.charCode< 48 || evt.charCode > 57) {
        evt.preventDefault( );
    }
} 
 

This method is the equivalent of assigning false to the IE event.returnValue property, or having an event handler evaluate to return false.

 
Parameters

None.

 
Returned Value

None.

stopPropagation( )NN 6 IE n/a DOM 2

Prevents the current event from propagating through the capture or bubbling hierarchy beyond the node currently processing the event. This method performs the same action as assigning false to the event object's cancelBubble property (for bubbling propagation only).

 
Parameters

None.

 
Returned Value

None.