event | NN 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). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Object Model Reference | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Properties | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Event Handler Properties | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
None. |
altKey | NN 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 |
altLeft | NN 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 |
attrChange | NN 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. |
||||||||||||
|
||||||||||||
Example | ||||||||||||
if (evt.attrChange == evt.MODIFICATION) { // do post-processing of attribute value change } |
||||||||||||
Value | ||||||||||||
Integer value: 1 | 2 | 3. |
||||||||||||
Default | ||||||||||||
None. |
attrName | NN 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, boundElements | NN 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. |
bubbles | NN 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. |
cancelable | NN 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. |
cancelBubble | NN 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 |
charCode | NN 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, clientY | NN 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. |
contentOverflow | NN 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 |
ctrlKey | NN 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 |
ctrlLeft | NN 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 |
currentTarget | NN 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. |
data | NN |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. |
dataFld | NN 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. |
dataTransfer | NN 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. |
detail | NN 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. |
eventPhase | NN 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. |
||||||||
|
||||||||
Default | ||||||||
2 |
fromElement | NN 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. |
isChar | NN 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 |
keyCode | NN 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, layerY | NN 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 |
metaKey | NN 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 |
modifiers | NN |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, prevValue | NN 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. |
nextPage | NN 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, offsetY | NN 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. |
originalTarget | NN 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, pageY | NN 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. |
propertyName | NN 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. |
qualifier | NN 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. |
rangeOffset | NN 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 |
rangeParent | NN 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. |
reason | NN 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: |
|
|
|
Default | |
None. |
recordset | NN 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. |
repeat | NN 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 |
returnValue | NN 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, screenY | NN 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 |
shiftKey | NN 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 |
shiftLeft | NN 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 |
srcElement | NN 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. |
srcFilter | NN 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. |
srcUrn | NN 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 |
target | NN 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. |
timeStamp | NN 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. |
toElement | NN 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. |
type | NN 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. |
view | NN 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. |
wheelDelta | NN 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. |
which | NN 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, y | NN 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 | |
|
|
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 | |
|
|
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 | |
|
|
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 | |
|
|
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 | |
|
|
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. |