Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

The DOM CompositionEvent represents events that occur due to the user indirectly entering text.

Method overview

void initCompositionEvent(in DOMString typeArg,in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString dataArg, in DOMString localeArg);

Attributes

Attribute Type Description
data DOMString

For compositionstart events, this is the currently selected text that will be replaced by the string being composed. This value doesn't change even if content changes the selection range; rather, it indicates the string that was selected when composition started.

For compositionupdate, this is the string as it stands currently as editing is ongoing.

For compositionend events, this is the string as committed to the editor.

Read only.

locale DOMString

The locale of current input method (for example, the keyboard layout locale if the composition is associated with IME). Read only.

Methods

initCompositionEvent

Initializes the attributes of a composition event.

void initCompositionEvent(
  in DOMString typeArg,
  in boolean canBubbleArg,
  in boolean cancelableArg,
  in views::AbstractView viewArg,
  in DOMString dataArg,
  in DOMString localeArg
);
Parameters
typeArg
The type of composition event; this will be one of compositionstart, compositionupdate, or compositionend.
canBubbleArg
Whether or not the event can bubble.
cancelableArg
Whether or not the event can be canceled.
viewArg
The window object from which the event was generated.
dataArg
The value of the data attribute.
localeArg
The value of the locale attribute.

Specifications

Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
The definition of 'CompositionEvent' in that specification.
Working Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 9.0 (9.0) (Yes) No support ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 9.0 (9.0) ? ? ?

Gecko notes

The compositionstart and compositionend events were fired in versions of Gecko before 9.0, but didn't have the DOM Level 3 attributes and methods. In addition, support for the compositionupdate event was added in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6).

Note: Gecko doesn't support the locale attribute for trusted events yet.  However, web developers can set this value via initCompositionEvent() when creating untrusted events.

Gecko's editors (for example, <input type="text">, <div contenteditable/>, and designMode) start composition after the bubble phase of compositionstart. So, by the time your compositionstart handler is called, no contents have not been modified.

Gecko's editors don't handle the compositionupdate event yet. By the time your compositionupdate handler is called, no contents have been modified.

By the time your compositionend event handler is called, composition is complete, and no further changes will occur. For that reason, if you call event.stopPropagation() on the compositionstart or compositionend event, you can break composition behavior and cause editors to fail to manage editing properly. See bug 697842 for progress on this problem getting fixed.

See also

Document Tags and Contributors

 Contributors to this page: gurdiga, fscholz, teoli, kscarfone, tregagnon, Sheppy, ethertank, Masayuki
 Last updated by: gurdiga,