Initializes a new text event that the createEvent method created.
Method of dom/TextEventdom/TextEvent
Syntax event.initTextEvent();
Parameters eventType
The name of the event. Sets the value for the type property. This parameter is case sensitive! Sets the type property of the event object.
For IE9 or higher use ‘textinput’ For Webkit use 'textInput’.
canBubbleWhether the event propagates upward. Sets the value for the bubbles property.
cancelableWhether the event is cancelable and so preventDefault can be called. Sets the value for the cancelable property.
viewThe window on which this event is occurring. Sets the value for the view property.
dataCharacter data. Sets the value for the data property.
inputMethodThe input mode for the text. Sets the value for the inputMethod property.
Required in Internet Explorer, not supported and omitted in Safari and Google Chrome. Integer that specifies the input mode for the text.
localeThe locale name. Sets the value for the locale property.
Required in Internet Explorer, not supported and omitted in Safari and Google Chrome. String that specifies the locale name of the text.
Return ValueNo return value
ExamplesThe below sample shows a click event handler that creates and dispatches either a ‘textinput’ or ‘textInput’ event (depending on the selected options) to textarea element.
function InsertText () {
try {
var newtextEvent = document.createEvent('TextEvent');
var textarea = document.getElementById ("textarea");
var intputmethod=eval(document.getElementById('cboinputmethod').value);
if(document.forms.frmTextEvent.chkontextinput.checked){
newtextEvent.initTextEvent ('textinput', true, true, null, "New text", intputmethod, "en-US");
}
else if(document.forms.frmTextEvent.chkontextInput.checked){
newtextEvent.initTextEvent ('textInput', true, true, null, "New text", intputmethod, "en-US");
}else{
alert('First choose the textinput or textInput event handler.'); return;
}
textarea.focus();
textarea.selectionStart = 0;
textarea.selectionEnd = 0;
textarea.dispatchEvent(newtextEvent);
}
catch (e) {
alert ('Your browser does not support this example!\nError :'+e);
}
}
The DOMInputMetod is present in the MSIE ‘textinput’ event handler only.
function getDOMInputMethod(iInputMethod){
switch (iInputMethod){
case TextEvent.DOM_INPUT_METHOD_UNKNOWN:
return 'Unknown';
case TextEvent.DOM_INPUT_METHOD_KEYBOARD:
return 'Keyboard';
case TextEvent.DOM_INPUT_METHOD_PASTE:
return 'Paste';
case TextEvent.DOM_INPUT_METHOD_DROP:
return 'Drop';
case TextEvent.DOM_INPUT_METHOD_IME:
return 'IME';
case TextEvent.DOM_INPUT_METHOD_OPTION:
return 'Option';
case TextEvent.DOM_INPUT_METHOD_HANDWRITING:
return 'Handwriting';
case TextEvent.DOM_INPUT_METHOD_VOICE:
return 'Voice';
case TextEvent.DOM_INPUT_METHOD_MULTIMODAL:
return 'MultiModal';
case TextEvent.DOM_INPUT_METHOD_SCRIPT:
return 'Script';
default:
return 'Unknown';
}
}
Usage
Used to emulate keyboard events from other input devices like on screen keyboard clicks, voice input, handwriting, copy and paste operations and scripted input methods.
Notes
The event type is case sensitive!
In Internet Explorer use ‘textinput’ for the eventType.
In Safari and Chromium use ‘textInput’ for the eventType parameter.
MSIE browsers further require that the event inputMethod isTrusted.
Related specificationsMicrosoft Developer Network: [initTextEvent Method Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4