Skip to content

Instantly share code, notes, and snippets.

@bryanforbes
Created April 11, 2011 16:23
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 bryanforbes/913797 to your computer and use it in GitHub Desktop.
Save bryanforbes/913797 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<input id="txt" />
<script>
var txt = document.getElementById("txt"),
e = document.createEvent("TextEvent");
e.initTextEvent("textInput", true, true, null, "a");
txt.focus();
txt.dispatchEvent(e);
/* The following is the sequence of events
* WebKit generates when hitting backspace
*/
e = document.createEvent("KeyboardEvent");
e.initKeyboardEvent("keydown", true, true, null, "U+0008", 0);
txt.dispatchEvent(e);
e = document.createEvent("Event");
e.initEvent("input", true, true, null);
txt.dispatchEvent(e);
e = document.createEvent("KeyboardEvent");
e.initKeyboardEvent("keyup", true, true, null, "U+0008", 0);
txt.dispatchEvent(e);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment