Table of Contents | Previous
| Next
| Index
The event
object contains properties that describe a JavaScript event, and is passed as an argument to an event handler when the event occurs.
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.
event
objects are created by Communicator when an event occurs. You do not create them yourself.
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.
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 .
| |
---|
This object inherits the watch
and unwatch
methods from Object
.
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>
For the DragDrop event, returns an array of strings containing the URLs of the dropped objects.
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.
Represents the height of the window or frame.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.width
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.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
This property is synonymous with the event.x
property.
event.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.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
This property is synonymous with the event.y
property.
event.layerX
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.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.which
Number specifying the cursor's horizontal position in pixels, relative to the page.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.pageY
Number specifying the cursor's vertical position in pixels relative to the page.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.pageX
Number specifying the cursor's horizontal position in pixels, relative to the screen.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.screenY
Number specifying the cursor's vertical position in pixels, relative to the screen.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.screenX
String representing the object to which the event was originally sent.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.type
String representing the event type.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.target
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.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.modifiers
Represents the width of the window or frame.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
event.height
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.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
This property is synonymous with the event.layerX
property.
event.y
Synonym for layerY
.
Setting this property requires the UniversalBrowserWrite
privilege. For information on security, see the Client-Side JavaScript Guide.
This property is synonymous with the event.layerY
property.
event.x
Table of Contents | Previous
| Next
| Index
Last Updated: 05/28/99 11:59:24
Copyright (c) 1999
Netscape Communications Corporation