Skip to content Skip to sidebar Skip to footer

Javascript, Simulate Keyboard Events, Work On Chrome(webkit)

in FF, i've used this code: if (keyCount == lineLimit) { // method in FF, no Chrome var mock = document.createEvent('KeyboardEvent'); // or KeysEvent mock.initKeyEve

Solution 1:

This works, but it's not generating a keypress-event, rather a text-insert event.

var te = document.createEvent('TextEvent');
te.initTextEvent('textInput', true, true, window, 'test');
<element>.dispatchEvent(te);

That inserts the word 'test' at the end of the input (in your case you'd probably replace that by \n.

Post a Comment for "Javascript, Simulate Keyboard Events, Work On Chrome(webkit)"