Skip to content

Instantly share code, notes, and snippets.

@adeolaawoyemi
Created June 15, 2012 00:02
Show Gist options
  • Save adeolaawoyemi/2933733 to your computer and use it in GitHub Desktop.
Save adeolaawoyemi/2933733 to your computer and use it in GitHub Desktop.
Simulate keypress usnig javascript (doesn't work in Safari or Chrome)
var elem = (document.getElementsByClassName('mentionsTextarea'))[0];
elem.value = 'www.youtube.com';
elem.blur();
elem.value += ' ';
var evt = document.createEvent('KeyboardEvent');
evt.initKeyEvent(
'keypress',
true, // key down events bubble
true, // and they can be cancelled
null, // Use the default view
false, // ctrl
false, // alt
false, //shift
false, //meta key
32, // Space keycode, use 13 for Enter
0
);
elem.dispatchEvent(evt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment