Skip to content

Instantly share code, notes, and snippets.

@flying19880517
Created July 26, 2012 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying19880517/3180456 to your computer and use it in GitHub Desktop.
Save flying19880517/3180456 to your computer and use it in GitHub Desktop.
initTextEvent Example
<html>
<head>
<!--
//http://help.dottoro.com/ljuecqgv.php
-->
<script type="text/javascript">
function Init () {
var textarea = document.getElementById ("textarea");
if (textarea.addEventListener) {
// Google Chrome and Safari
textarea.addEventListener ('textInput', OnTextInput, false);
// Internet Explorer from version 9
textarea.addEventListener ("textinput", OnTextInput, false);
}
}
function InsertText () {
try {
var textEvent = document.createEvent('TextEvent');
textEvent.initTextEvent ('textInput', true, true, null, "New text", 9, "en-US");
var textarea = document.getElementById ("textarea");
textarea.selectionStart = 0;
textarea.selectionEnd = 0;
textarea.dispatchEvent(textEvent);
}
catch (e) {
alert ("Your browser does not support this example!");
}
}
function OnTextInput (event) {
alert ("The inserted content: " + event.data);
}
</script>
</head>
<body onload="Init ();">
<textarea id="textarea">Textarea</textarea>
<button onclick="InsertText ()">Insert text at the front of the textarea</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment