event Object

DHTML, HTML, & CSS

event Object


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.

Remarks

The event object is available only during an event—that is, you can use it in event handlers but not in other code.

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.

In Microsoft® Visual Basic® Scripting Edition (VBScript), you must access the event object through the window object.

This object is available in script as of Microsoft® Internet Explorer 4.0.

Members

Example

This example uses the event object to check whether the user clicked the mouse within a link, and to prevent the link from being navigated 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()">

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

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

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
window

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.