Packagedom.events
Classpublic class UIEvent
InheritanceUIEvent Inheritance Event Inheritance Object
Subclasses KeyboardEvent, KeyEvent, MouseEvent, TextEvent

Introduced in: DOM 2 Events 
Modified in: DOM 3 Events 

The UIEvent interface provides specific contextual information associated with User Interface events.

To create an instance of the UIEvent interface, use the DocumentEvent.createEvent("UIEvent") method call.

See also

MDC - event
W3C - DOM 3 Events: UIEvent


Public Properties
 PropertyDefined By
 InheritedDOM 2 Events bubbles : Boolean
[read-only] Used to indicate whether or not an event is a bubbling event.
Event
 InheritedDOM 2 Events cancelable : Boolean
[read-only] Indicates whether the event is cancelable or not.
Event
 InheritedDOM 2 Events currentTarget : EventTarget
[read-only] Identifies the current target for the event, as the event traverses the DOM.
Event
 InheritedDOM 3 Events defaulPrevented : Boolean
[read-only] Used to indicate whether Event.preventDefault() has been called for this event.
Event
  DOM 2 Events detail : Number
[read-only] Specifies some detail information about the Event, depending on the type of event.
UIEvent
 InheritedDOM 2 Events eventPhase : Number
[read-only] Used to indicate which phase of event flow is currently being accomplished.
Event
 InheritedNon-Standard explicitOriginalTarget : nsIDOMEventTarget
[read-only] The explicit original target of the event.
Event
  Non-Standard isChar : Boolean
[read-only] Returns a boolean indicating whether the event produced a key character or not.
UIEvent
 InheritedNon-Standard isTrusted : Boolean
[read-only] Determines if the event was from the user or script generated.
Event
  Non-Standard layerX : Number
[read-only] Returns the horizontal coordinate of the event relative to the current layer.
UIEvent
  Non-Standard layerY : Number
[read-only] Returns the vertical coordinate of the event relative to the current layer.
UIEvent
 InheritedDOM 3 Events namespaceURI : DOMString
[read-only] The namespace URI associated with this event at initialization time, or null if it is unspecified.
Event
 InheritedNon-Standard originalTarget : *
[read-only] The original target of the event before any retargetings.
Event
  Non-Standard pageX : Number
[read-only] Returns the horizontal coordinate of the event relative to whole document.
UIEvent
  Non-Standard pageY : Number
[read-only] Returns the vertical coordinate of the event relative to the whole document.
UIEvent
 InheritedDOM 2 Events target : EventTarget
[read-only] Used to indicate the event target.
Event
 InheritedDOM 2 Events timeStamp : DOMTimeStamp
[read-only] Used to specify the time at which the event was created in milliseconds relative to 1970-01-01T00:00:00Z.
Event
 InheritedDOM 2 Events type : DOMString
[read-only] The local name of the event type.
Event
  DOM 2 Events view : AbstractView
[read-only] Returns the AbstractView object from which the event was generated.
UIEvent
  Non-Standard which : DOMString
[read-only] Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.
UIEvent
Public Methods
 MethodDefined By
 Inherited
DOM 2 Events initEvent(typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void
Initializes attributes of an Event created through the DocumentEvent.createEvent method.
Event
 Inherited
DOM 3 Events initEventNS(namespaceURIArg:DOMString, typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void
Initializes attributes of an Event object.
Event
  
DOM 2 Events initUIEvent(typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean, viewArg:AbstractView, detailArg:Number):void
Initializes attributes of an UIEvent object.
UIEvent
  
DOM 3 Events initUIEventNS(namespaceURIArg:DOMString, typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean, viewArg:AbstractView, detailArg:Number):void
Initializes attributes of an UIEvent object.
UIEvent
 Inherited
 Obsolete preventBubble():void
Prevents the event from bubbling.
Event
 Inherited
 Obsolete preventCapture():void
This method is deprecated in favor of standard stopPropagation and is removed in Gecko 1.9.
Event
 Inherited
DOM 2 Events preventDefault():void
Cancels the event if it is cancelable, without stopping further propagation of the event.
Event
 Inherited
DOM 3 Events stopImmediatePropogation():void
Prevents other event listeners from being triggered and, unlike Event.stopPropagation() its effect is immediate .
Event
 Inherited
DOM 2 Events stopPropogation():void
Prevents other event listeners from being triggered but its effect is deferred until all event listeners attached on the Event.currentTarget have been triggered .
Event
Public Constants
 ConstantDefined By
  HTML 4.0 abort : String = abort
[static] Loading of a resource has been aborted.
UIEvent
 InheritedDOM 2 Events AT_TARGET : Number = 2
[static] The current event is in the target phase, i.e.
Event
  DOM 2 Events blur : String = blur
[static] An event target loses focus.
UIEvent
 InheritedDOM 2 Events BUBBLING_PHASE : Number = 3
[static] The current event phase is the bubbling phase.
Event
 InheritedDOM 2 Events CAPTURING_PHASE : Number = 1
[static] The current event phase is the capture phase.
Event
  HTML 4.0 change : String = change
[static] A control loses the input focus and its value has been modified since gaining focus.
UIEvent
  DOM 2 Events DOMActivate : String = DOMActivate
[static] Refer to Activation requests and behavior.
UIEvent
  DOM 2 Events DOMFocusIn : String = DOMFocusIn
[static] An event target receives focus.
UIEvent
  DOM 2 Events DOMFocusOut : String = DOMFocusOut
[static] An event target loses focus.
UIEvent
  HTML 4.0 error : String = error
[static] A resource failed to load, or has been loaded but cannot be interpreted according to its semantics such as an invalid image, a script execution error, or non-well-formed XML.
UIEvent
  DOM 2 Events focus : String = focus
[static] An event target receives focus.
UIEvent
  HTML 4.0 load : String = load
[static] The DOM Implementation finishes loading the resource (such as the document) and any dependent resources (such as images, style sheets, or scripts).
UIEvent
  HTML 4.0 reset : String = reset
[static] A form, such as a [HTML 4.01] or [XHTML 1.0] form, is reset.
UIEvent
  DOM 2 Events resize : String = resize
[static] A document view or an element has been resized.
UIEvent
  DOM 2 Events scroll : String = scroll
[static] A document view or an element has been scrolled.
UIEvent
  HTML 4.0 select : String = select
[static] A user selects some text.
UIEvent
  HTML 4.0 submit : String = submit
[static] A form, such as a [HTML 4.01] or [XHTML 1.0] form, is submitted.
UIEvent
  HTML 4.0 unload : String = unload
[static] The DOM implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts).
UIEvent
Property Detail
DOM 2 Events detailproperty
detail:Number  [read-only]

Introduced in: DOM 2 Events 

Specifies some detail information about the Event, depending on the type of event.

Note: For mouse events, such as click, dblclick, mousedown, or mouseup, the detail property indicates how many times the mouse has been clicked in the same location for this event.

Note: For a dblclick event the value of detail is always 2.


Implementation
    public function get detail():Number

See also


Example
         <html>
         <head>
             <title>event.detail example</title>
             <script type="text/javascript">
             function giveDetails(e) {
                 var text = document.getElementById("t");
                 text.value = e.detail;
             }
             function init() {
                 var b1 = document.getElementById("b");
                 b1.onclick = giveDetails;   
             }
             </script>
         
         </head>
         <body onload="init();">
         <form>
             <input id="b" type="button" value="details">
             <input id="t" type="text" value=""><br>
             <input type="reset">
         </form>
         </body>
         </html>
isCharproperty 
isChar:Boolean  [read-only]

Non-standard (Mozilla)

Returns a boolean indicating whether the event produced a key character or not.

Note: Some key combos may raise events but not produce any character (example: ctrl + alt ?). When this is the case, isChar returns false. isChar is used when event handlers need to do something like echo the input on the screen.

Note: There is currently a known bug affecting the return result, which is always false and never true. Please see the discussion link in the sidebar for more details.


Implementation
    public function get isChar():Boolean

See also


Example
         if e.isChar {
             echoInput(e.type);
         }
layerXproperty 
layerX:Number  [read-only]

Non-standard (Mozilla)

Returns the horizontal coordinate of the event relative to the current layer.

Note: layerX takes scrolling of the page into account, and returns a value relative to the whole of the document, unless the event occurs inside a positioned element, where the returned value is relative to the top left of the positioned element.


Implementation
    public function get layerX():Number

See also


Example
         <html>
        <head>
        <title>pageX\pageY & layerX\layerY example</title>

        <script type="text/javascript">

        function showCoords(evt){
          var form = document.forms.form_coords;
          var parent_id = evt.target.parentNode.id;
          form.parentId.value = parent_id;
          form.pageXCoords.value = evt.pageX;
          form.pageYCoords.value = evt.pageY;
          form.layerXCoords.value = evt.layerX;
          form.layerYCoords.value = evt.layerY;
        }
        </script>

        <style type="text/css">

         #d1 {
          border: solid blue 1px;
          padding: 20px;
         }

         #d2 {
          position: absolute;
          top: 180px;
          left: 80%;
          right:auto;
          width: 40%;
          border: solid blue 1px;
          padding: 20px;
         }

         #d3 {
          position: absolute;
          top: 240px;
          left: 20%;
          width: 50%;
          border: solid blue 1px;
          padding: 10px;
         }

        </style>
        </head>

        <body onmousedown="showCoords(event)">

        <p>To display the mouse coordinates please click anywhere on the page.</p>

        <div id="d1">
        <span>This is an un-positioned div so clicking it will return
        layerX/layerY values almost the same as pageX/PageY values.</span>
        </div>

        <div id="d2">

        <span>This is a positioned div so clicking it will return layerX/layerY
        values that are relative to the top-left corner of this positioned
        element. Note the pageX\pageY properties still return the
        absolute position in the document, including page scrolling.</span>

        <span>Make the page scroll more! This is a positioned div so clicking it
        will return layerX/layerY values that are relative to the top-left
        corner of this positioned element. Note the pageX\pageY properties still
        return the absolute position in the document, including page
        scrolling.</span>

        </div>

        <div id="d3">
        <form name="form_coords" id="form1">
         Parent Element id: <input type="text" name="parentId" size="7" /><br />

         pageX:<input type="text" name="pageXCoords" size="7" />  
         pageY:<input type="text" name="pageYCoords" size="7" /><br />
         layerX:<input type="text" name="layerXCoords" size="7" />  
         layerY:<input type="text" name="layerYCoords" size="7" />

        </form>
        </div>

        </body>
        </html>
layerYproperty 
layerY:Number  [read-only]

Non-standard (Mozilla)

Returns the vertical coordinate of the event relative to the current layer.

Note: layerY takes scrolling of the page into account, and returns a value relative to the whole of the document, unless the event occurs inside a positioned element, where the returned value is relative to the top left of the positioned element.


Implementation
    public function get layerY():Number

See also


Example
         <html>
        <head>
        <title>pageX\pageY & layerX\layerY example</title>

        <script type="text/javascript">

        function showCoords(evt){
          var form = document.forms.form_coords;
          var parent_id = evt.target.parentNode.id;
          form.parentId.value = parent_id;
          form.pageXCoords.value = evt.pageX;
          form.pageYCoords.value = evt.pageY;
          form.layerXCoords.value = evt.layerX;
          form.layerYCoords.value = evt.layerY;
        }
        </script>

        <style type="text/css">

         #d1 {
          border: solid blue 1px;
          padding: 20px;
         }

         #d2 {
          position: absolute;
          top: 180px;
          left: 80%;
          right:auto;
          width: 40%;
          border: solid blue 1px;
          padding: 20px;
         }

         #d3 {
          position: absolute;
          top: 240px;
          left: 20%;
          width: 50%;
          border: solid blue 1px;
          padding: 10px;
         }

        </style>
        </head>

        <body onmousedown="showCoords(event)">

        <p>To display the mouse coordinates please click anywhere on the page.</p>

        <div id="d1">
        <span>This is an un-positioned div so clicking it will return
        layerX/layerY values almost the same as pageX/PageY values.</span>
        </div>

        <div id="d2">

        <span>This is a positioned div so clicking it will return layerX/layerY
        values that are relative to the top-left corner of this positioned
        element. Note the pageX\pageY properties still return the
        absolute position in the document, including page scrolling.</span>

        <span>Make the page scroll more! This is a positioned div so clicking it
        will return layerX/layerY values that are relative to the top-left
        corner of this positioned element. Note the pageX\pageY properties still
        return the absolute position in the document, including page
        scrolling.</span>

        </div>

        <div id="d3">
        <form name="form_coords" id="form1">
         Parent Element id: <input type="text" name="parentId" size="7" /><br />

         pageX:<input type="text" name="pageXCoords" size="7" />  
         pageY:<input type="text" name="pageYCoords" size="7" /><br />
         layerX:<input type="text" name="layerXCoords" size="7" />  
         layerY:<input type="text" name="layerYCoords" size="7" />

        </form>
        </div>

        </body>
        </html>
pageXproperty 
pageX:Number  [read-only]

Non-standard (Mozilla)

Returns the horizontal coordinate of the event relative to whole document.


Implementation
    public function get pageX():Number

See also

pageYproperty 
pageY:Number  [read-only]

Non-standard (Mozilla)

Returns the vertical coordinate of the event relative to the whole document.


Implementation
    public function get pageY():Number

See also

DOM 2 Events viewproperty 
view:AbstractView  [read-only]

Introduced in: DOM 2 Events 

Returns the AbstractView object from which the event was generated. In browsers, this is the window object the event happened in.


Implementation
    public function get view():AbstractView

See also

whichproperty 
which:DOMString  [read-only]

Non-standard (Mozilla)

Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.


Implementation
    public function get which():DOMString

See also


Example
         <html>
         <head>
         <title>charCode/keyCode/which example</title>
         
         <script type="text/javascript">
         
         function showKeyPress(evt) {
             alert("onkeypress handler: \n"
                 + "keyCode property: " + evt.keyCode + "\n"
                 + "which property: " + evt.which + "\n"
                 + "charCode property: " + evt.charCode + "\n"
                 + "Character Key Pressed: "
                 + String.fromCharCode(evt.charCode) + "\n"
             );
         }
         
         
         function keyDown(evt) {
             alert("onkeydown handler: \n"
                 + "keyCode property: " + evt.keyCode + "\n"
                 + "which property: " + evt.which + "\n"
             );
         }
         
         
         </script>
         </head>
         
         <body
           onkeypress="showKeyPress(event);"
           onkeydown="keyDown(event);"
         >
         
         <p>Please press any key.</p>
         
         </body>
         </html>
Method Detail
DOM 2 Events initUIEvent()method
public function initUIEvent(typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean, viewArg:AbstractView, detailArg:Number):void

Introduced in: DOM 2 Events 

Initializes attributes of an UIEvent object. This method has the same behavior as Event.initEvent().

Parameters

typeArg:DOMString — Specifies Event.type, the local name of the event type.
 
canBubbleArg:Boolean — Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.
 
cancelableArg:Boolean — Specifies Event.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.
 
viewArg:AbstractView — Specifies UIEvent.view. This value may be null.
 
detailArg:Number — Specifies UIEvent.detail.

See also


Example
         e = document.createEvent("UIEvents");
         // creates a click event that bubbles, can be cancelled,
         // and with its view and detail property initialized to window and 1,
         // respectively
         e.initUIEvent("click", true, true, window, 1);
DOM 3 Events initUIEventNS()method 
public function initUIEventNS(namespaceURIArg:DOMString, typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean, viewArg:AbstractView, detailArg:Number):void

Introduced in: DOM 3 Events 

Initializes attributes of an UIEvent object. This method has the same behavior as Event.initEventNS().

Parameters

namespaceURIArg:DOMString — Specifies Event.namespaceURI, the namespace URI associated with this event, or null if no namespace.
 
typeArg:DOMString — Specifies Event.type, the local name of the event type.
 
canBubbleArg:Boolean — Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.
 
cancelableArg:Boolean — Specifies Event.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.
 
viewArg:AbstractView — Specifies UIEvent.view. This value may be null.
 
detailArg:Number — Specifies UIEvent.detail.

See also

Constant Detail
HTML 4.0 abortConstant
public static const abort:String = abort

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

Loading of a resource has been aborted.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events blurConstant 
public static const blur:String = blur

Introduced in: DOM 2 Events 

An event target loses focus. The focus is taken from the element before the dispatch of this event type.

TitleValue
CancelableNo
BubblesNo
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 changeConstant 
public static const change:String = change

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A control loses the input focus and its value has been modified since gaining focus. This event type is dispatched before the event type blur.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events DOMActivateConstant 
public static const DOMActivate:String = DOMActivate

Introduced in: DOM 2 Events 

Refer to Activation requests and behavior.

TitleValue
NamespaceNone
CancelableYes
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events DOMFocusInConstant 
public static const DOMFocusIn:String = DOMFocusIn

Introduced in: DOM 2 Events 

An event target receives focus. The focus is given to the element before the dispatch of this event type. This event type is dispatched after the event type focus.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events DOMFocusOutConstant 
public static const DOMFocusOut:String = DOMFocusOut

Introduced in: DOM 2 Events 

An event target loses focus. The focus is taken from the element before the dispatch of this event type. This event type is dispatched after the event type blur.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 errorConstant 
public static const error:String = error

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A resource failed to load, or has been loaded but cannot be interpreted according to its semantics such as an invalid image, a script execution error, or non-well-formed XML.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events focusConstant 
public static const focus:String = focus

Introduced in: DOM 2 Events 

An event target receives focus. The focus is given to the element before the dispatch of this event type.

TitleValue
CancelableNo
BubblesNo
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 loadConstant 
public static const load:String = load

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

The DOM Implementation finishes loading the resource (such as the document) and any dependent resources (such as images, style sheets, or scripts). Dependent resources that fail to load will not prevent this event from firing if the resource that loaded them is still accessible via the DOM. If this event type is dispatched, implementations are required to dispatch this event at least on the Document node.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesNo
TargetDocument, Element
Context infoUIEvent.view is in use.

See also

HTML 4.0 resetConstant 
public static const reset:String = reset

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A form, such as a [HTML 4.01] or [XHTML 1.0] form, is reset.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableYes
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events resizeConstant 
public static const resize:String = resize

Introduced in: DOM 2 Events 

A document view or an element has been resized. The resize occured before the dispatch of this event type.

TitleValue
CancelableNo
BubblesYes
TargetDocument, Element
Context infoUIEvent.view is in use.

See also

DOM 2 Events scrollConstant 
public static const scroll:String = scroll

Introduced in: DOM 2 Events 

A document view or an element has been scrolled. The scroll occured before the dispatch of this event type.

TitleValue
CancelableNo
BubblesYes
TargetDocument, Element
Context infoUIEvent.view is in use.

See also

HTML 4.0 selectConstant 
public static const select:String = select

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A user selects some text. DOM Level 3 Events does not provide contextual information to access the selected text. The selection occured before the dispatch of this event type.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 submitConstant 
public static const submit:String = submit

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A form, such as a [HTML 4.01] or [XHTML 1.0] form, is submitted.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableYes
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 unloadConstant 
public static const unload:String = unload

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

The DOM implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts). The document is unloaded after the dispatch of this event type. If this event type is dispatched, implementations are required to dispatch this event at least on the Document node.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesNo
TargetDocument, Element
Context infoUIEvent.view is in use.

See also