user2069499
user2069499

Reputation: 49

Simulate ctrl+v event on javascript

I try to simulate Ctrl+V in javascript. I use firefox in Linux. What I do is:

var pressEvent = document.createEvent ("KeyboardEvent");    
pressEvent.initKeyEvent ("keypress", true, true, window, true, false, false, false, 86, 0);
var accepted=aTarget.dispatchEvent (pressEvent);

Somebody knows why it doesn't work??

Thanks

Upvotes: 4

Views: 11851

Answers (1)

TheBrain
TheBrain

Reputation: 5608

Copy and Paste and the clipoard itself are very protected. Unless there is explicit user action it won't work with simulations. If you make a script that simulates a paste inside a inputbox then submit that to your server, you might get some really private info from people clipboards. So...no, that won't work to my knowledge. I would love for you or someone else to prove me wrong and share the solution.

But do tell what you're planning to do and maybe there's a workaround it that doesn't involve this simulated action.

Upvotes: 6

Related Questions