Event object (Object/DOM)

Early Netscape and MSIE browsers define different event object models. In MSIE, a single Event object is available globally and shared by all events.

Availability:

DOM level - 2
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
JavaScript syntax:-myEvent = event
-myEvent = myWindow.event
NmyEvent = myDocumentEvent.createEvent(aType)
Argument list:aTypeAn event type
Object properties:altKey, bubbles, button, cancelable, cancelBubble, charCode, clientX, clientY, ctrlKey, currentTarget, data, dataFld, dataTransfer, eventPhase, fromElement, height, keyCode, layerX, layerY, modifiers, offsetX, offsetY, pageX, pageY, propertyName, qualifier, reason, recordset, repeat, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, srcUrn, target, timeStamp, toElement, type, which, width, x, y
Class constants:ABORT, ALT_MASK, AT_TARGET, BACK, BLUR, BUBBLING_PHASE, CAPTURING_PHASE, CHANGE, CLICK, CONTROL_MASK, DBLCLICK, DRAGDROP, ERROR, FOCUS, FORWARD, HELP, KEYDOWN, KEYPRESS, KEYUP, LOAD, LOCATE, META_MASK, MOUSEDOWN, MOUSEDRAG, MOUSEMOVE, MOUSEOUT, MOUSEOVER, MOUSEUP, MOVE, RESET, RESIZE, SCROLL, SELECT, SHIFT_MASK, SUBMIT, UNLOAD, XFER_DONE
Object methods:initEvent(), preventDefault(), stopPropagation()
Collections:bookmarks[], boundElements[]

The event models in Netscape version 4 and MSIE version 4 support an Event object. However, both browsers support different properties for this object. It may be possible with some smart JavaScript code to normalize these to look like the same object model. You could either define your own or take one and emulate it in the other.

As well as being different, the Event object is passed to event handlers in a different way for each browser. Netscape version 4 passes the Event object as an argument. MSIE version 4 stores a reference to it in the global variable called event.

Netscape provides a set of static constants that can be used to manufacture modifier masks. These can then be tested against the Event.modifiers property. These constants have names that all end with the suffix "_MASK". There are other constants provided so masks for event types can be made. These can be tested against the Event.type property.

MSIE does not support these static constants in the same way and uses fully spelled-out event names as string primitive values for matching. This ultimately may be better because Netscape is constrained for space as regards bit values for new events. There are only 32 bits and most have already been allocated to event types.

As of version 6.0 of Netscape, the underlying event model is based on the DOM level 2 event module. This is fundamentally different to the support of events in earlier versions of the Netscape browser. DOM level 2 and Netscape 6.0 converge on the same basic model as MSIE. This adds some new properties, methods and static constants in accordance with the DOM specification. Some properties persist from earlier versions.

The DOM level 2 specification for events describes a category of HTMLEvents which it suggests is based on DOM level 0 capabilities. There is only a small amount of information about the event type strings and the event capabilities in the DOM level 2 context. No ECMAScript binding is described and because DOM level 0 has never been published as a standard, there is a little ambiguity about these events. The standardization is somewhat de-facto regarding them and in due course, as the DOM event model evolves, this should all become more consistent and more completely documented.

Warnings:

Example code:

   // List the event constants in Netscape.

   // This does not work in MSIE.

   d  = document;

   e  = Event;

   s1 = "<TR><TD>";

   s2 = "</TD><TD>";

   s3 = "</TD></TR>";

   d.write("<TABLE BORDER=1>");

   d.write(s1 + "MOUSEDOWN" + s2 + e.MOUSEDOWN + s3);

   d.write(s1 + "MOUSEUP"   + s2 + e.MOUSEUP   + s3);

   d.write(s1 + "MOUSEOVER" + s2 + e.MOUSEOVER + s3);

   d.write(s1 + "MOUSEOUT"  + s2 + e.MOUSEOUT  + s3);

   d.write(s1 + "MOUSEMOVE" + s2 + e.MOUSEMOVE + s3);

   d.write(s1 + "CLICK"     + s2 + e.CLICK     + s3);

   d.write(s1 + "DBLCLICK"  + s2 + e.DBLCLICK  + s3);

   d.write(s1 + "KEYDOWN"   + s2 + e.KEYDOWN   + s3);

   d.write(s1 + "KEYUP"     + s2 + e.KEYUP     + s3);

   d.write(s1 + "KEYPRESS"  + s2 + e.KEYPRESS  + s3);

   d.write(s1 + "DRAGDROP"  + s2 + e.DRAGDROP  + s3);

   d.write(s1 + "FOCUS"     + s2 + e.FOCUS     + s3);

   d.write(s1 + "BLUR"      + s2 + e.BLUR      + s3);

   d.write(s1 + "SELECT"    + s2 + e.SELECT    + s3);

   d.write(s1 + "CHANGE"    + s2 + e.CHANGE    + s3);

   d.write(s1 + "RESET"     + s2 + e.RESET     + s3);

   d.write(s1 + "SUBMIT"    + s2 + e.SUBMIT    + s3);

   d.write(s1 + "LOAD"      + s2 + e.LOAD      + s3);

   d.write(s1 + "UNLOAD"    + s2 + e.UNLOAD    + s3);

   d.write(s1 + "ABORT"     + s2 + e.ABORT     + s3);

   d.write(s1 + "ERROR"     + s2 + e.ERROR     + s3);

   d.write(s1 + "MOVE"      + s2 + e.MOVE      + s3);

   d.write(s1 + "RESIZE"    + s2 + e.RESIZE    + s3);

   d.write("</TABLE>");

See also:Element.onevent, Event bubbling, Event handler, Event type constants, Event.modifiers, Implementation.hasFeature(), MouseEvent object, Timer events, UIEvent object, UniversalBrowserAccess, UniversalBrowserRead, UniversalBrowserWrite, unwatch(), watch(), Window.handleEvent()

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
altKey n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
bubbles1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/aReadOnly
button n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly
cancelable1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/aReadOnly
cancelBubble n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/a-
charCode n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
clientX n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
clientY n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
ctrlKey n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
currentTarget1.5 1.5 n/a6.0 6.0 n/a5.0 5.0 n/a n/a2 2 n/a n/aReadOnly
data1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly
dataFld1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning
dataTransfer n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
eventPhase1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/aReadOnly
fromElement n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
height1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
keyCode n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
layerX1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly
layerY1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly
modifiers1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aReadOnly
offsetX n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly
offsetY n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly
pageX1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aReadOnly
pageY1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aReadOnly
propertyName n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
qualifier1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning
reason n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
recordset1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning
repeat n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
returnValue n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
screenX1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
screenY1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
shiftKey n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/aReadOnly
srcElement n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
srcFilter n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
srcUrn1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a2 2 n/a n/aWarning
target1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a2 2 n/a n/aReadOnly
timeStamp1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/aWarning , ReadOnly
toElement n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
type1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a n/a2 2 n/a n/aReadOnly
which1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly
width1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
x1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
y1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
initEvent()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a2 2 n/a n/a-
preventDefault()1.5 1.5 n/a6.0 6.0 n/a5.0 5.0 n/a n/a2 2 n/a n/a-
stopPropagation()1.5 1.5 n/a6.0 6.0 n/a5.0 5.0 n/a n/a2 2 n/a n/a-