eventevent*
*Contents  *Index  *Topic Contents
*Previous Topic: EMBED
*Next Topic: external

event

Description

Represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.

The event object is available only during an event. That is, you can use it in event handlers but not in other code. You retrieve the event object by applying the event keyword to the window object.

Although all event properties are available to all event objects, some properties might not have meaningful values during some events. For example, the fromElement and toElement properties are meaningful only when processing the onmouseover and onmouseout events.

Examples

The following example checks whether a mouse click occurred within a link and prevents the link from being carried out if the SHIFT key is down.

<HTML>
<HEAD><TITLE>Cancels Links</TITLE>
<SCRIPT LANGUAGE="JScript">
function cancelLink() {
    if (window.event.srcElement.tagName == "A" && window.event.shiftKey) 
        window.event.returnValue = false;
}
</SCRIPT>
<BODY onclick="cancelLink()">

The following example displays the current mouse position in the browser's status window.

<BODY onmousemove="window.status = 'X=' + window.event.x + ' Y=' + window.event.y">

Note that in VBScript you cannot use the event keyword without applying it to the window keyword or an expression that evaluates to a window.

Properties

altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, reason, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y

Applies To

window


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.