Table of Contents | Previous | Next | Index


event

The event object contains properties that describe a JavaScript event, and is passed as an argument to an event handler when the event occurs.

Client-side object

Implemented in

JavaScript 1.2

In the case of a mouse-down event, for example, the event object contains the type of event (in this case MouseDown), the x and y position of the cursor at the time of the event, a number representing the mouse button used, and a field containing the modifier keys (Control, Alt, Meta, or Shift) that were depressed at the time of the event. The properties used within the event object vary from one type of event to another. This variation is provided in the descriptions of individual event handlers.

See Chapter 3, "Event Handlers," for complete information about event handlers. For more information on handling events, see the Client-Side JavaScript Guide.

Created by

event objects are created by Communicator when an event occurs. You do not create them yourself.

Security

Setting any property of this object requires the UniversalBrowserWrite privilege. In addition, getting the data property of the DragDrop event requires the UniversalBrowserRead privilege. For information on security, see the Client-Side JavaScript Guide.

Property Summary

Not all of these properties are relevant to each event type. To learn which properties are used by an event, see the "Event object properties used" section of the individual event handler.

Property Description
data

Returns an array of strings containing the URLs of the dropped objects. Passed with the DragDrop event.

height

Represents the height of the window or frame.

layerX

Number specifying either the object width when passed with the resize event, or the cursor's horizontal position in pixels relative to the layer in which the event occurred. Note that layerX is synonymous with x.

layerY

Number specifying either the object height when passed with the resize event, or the cursor's vertical position in pixels relative to the layer in which the event occurred. Note that layerY is synonymous with y.

modifiers

String specifying the modifier keys associated with a mouse or key event. Modifier key values are: ALT_MASK, CONTROL_MASK, SHIFT_MASK, and META_MASK.

pageX

Number specifying the cursor's horizontal position in pixels, relative to the page.

pageY

Number specifying the cursor's vertical position in pixels relative to the page.

screenX

Number specifying the cursor's horizontal position in pixels, relative to the screen.

screenY

Number specifying the cursor's vertical position in pixels, relative to the screen.

target

String representing the object to which the event was originally sent. (All events)

type

String representing the event type. (All events)

which

Number specifying either the mouse button that was pressed or the ASCII value of a pressed key. For a mouse, 1 is the left button, 2 is the middle button, and 3 is the right button.

width

Represents the width of the window or frame.

x

Synonym for layerX.

y

Synonym for layerY.

Method Summary

This object inherits the watch and unwatch methods from Object.

Examples

The following example uses the event object to provide the type of event to the alert message.

<A HREF="http://home.netscape.com" onClick='alert("Link got an event: "
+ event.type)'>Click for link event</A>
The following example uses the event object in an explicitly called event handler.

<SCRIPT>
function fun1(evnt) {
   alert ("Document got an event: " + evnt.type);
   alert ("x position is " + evnt.layerX);
   alert ("y position is " + evnt.layerY);
   if (evnt.modifiers & Event.ALT_MASK)
      alert ("Alt key was down for event.");
   return true;
   }
document.onmousedown = fun1;
</SCRIPT>

data

For the DragDrop event, returns an array of strings containing the URLs of the dropped objects.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. In addition, getting this property for the DragDrop event requires the UniversalBrowserRead privilege. For information on security, see the Client-Side JavaScript Guide.


height

Represents the height of the window or frame.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.width


layerX

Number specifying either the object width when passed with the resize event, or the cursor's horizontal position in pixels relative to the layer in which the event occurred.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

Description

This property is synonymous with the event.x property.

See also

event.layerY


layerY

Number specifying either the object height when passed with the resize event, or the cursor's vertical position in pixels relative to the layer in which the event occurred.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

Description

This property is synonymous with the event.y property.

See also

event.layerX


modifiers

String specifying the modifier keys associated with a mouse or key event. Modifier key values are: ALT_MASK, CONTROL_MASK, SHIFT_MASK, and META_MASK.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.which


pageX

Number specifying the cursor's horizontal position in pixels, relative to the page.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.pageY


pageY

Number specifying the cursor's vertical position in pixels relative to the page.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.pageX


screenX

Number specifying the cursor's horizontal position in pixels, relative to the screen.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.screenY


screenY

Number specifying the cursor's vertical position in pixels, relative to the screen.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.screenX


target

String representing the object to which the event was originally sent.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.type


type

String representing the event type.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.target


which

Number specifying either the mouse button that was pressed or the ASCII value of a pressed key. For a mouse, 1 is the left button, 2 is the middle button, and 3 is the right button.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.modifiers


width

Represents the width of the window or frame.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

See also

event.height


x

Number specifying either the object width when passed with the resize event, or the cursor's horizontal position in pixels relative to the layer in which the event occurred.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

Description

This property is synonymous with the event.layerX property.

See also

event.y


y

Synonym for layerY.

Property of

event

Implemented in

JavaScript 1.2

Security

Setting this property requires the UniversalBrowserWrite privilege. For information on security, see the Client-Side JavaScript Guide.

Description

This property is synonymous with the event.layerY property.

See also

event.x


Table of Contents | Previous | Next | Index

Last Updated: 05/28/99 11:59:24

Copyright (c) 1999 Netscape Communications Corporation