Created
July 26, 2012 05:42
-
-
Save flying19880517/3180456 to your computer and use it in GitHub Desktop.
initTextEvent Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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