ime-keydown-preventdefault.html   [plain text]

<p>Typing in the input fields below should not generate text, even with an IME enabled.</p>

Type into the input:
<input type=text id='input'></input><br>
<div id='out' style="float: right"></div>
Or the text area:
<textarea id='area'></textarea><br>
Or the contentEditable area:
<div contentEditable id='ce' style="border:1px solid red; height:300px; width:300px;"></div>
var input = document.getElementById('input');
var area = document.getElementById('area');
var ce = document.getElementById('ce');

var handleKeyDown = function(e) {
  document.getElementById('out').innerHTML += "<br>Got a key event -- cancelling";

input.addEventListener('keydown', handleKeyDown, false);
area.addEventListener('keydown', handleKeyDown, false);
ce.addEventListener('keydown', handleKeyDown, false);