7

I know this topic discussed many times. But this one a bit different. I need to "dispatch" a "paste" event (like after copy "paste").

Why do I need that ? Well when you copying a link into a message textarea in Facebook,you see that automatically ajax script called that alters the page so that recipient could see attached image besides the link.

since I'm not going to use Facebook API's and stuff,I just want to call the paste event that hopefully will trigger the script that I need.

Lix
  • 47,311
  • 12
  • 103
  • 131
Ivelius
  • 4,953
  • 7
  • 30
  • 54
  • What you seek is probably `keydown`/`keyup` events witch comparison of textarea value from before and after... – Juicy Scripter Jan 09 '12 at 14:33
  • Are you clear about the difference between *dispatching* an event and *handling* an event? The browser will already fire a "paste" event when the user does a paste operation on your input elements. – Pointy Jan 09 '12 at 14:35
  • I know the difference between dispatching an event and handling it.And what I need is to "dispatch" one.If you know how to make a browser "fire" the "paste" event programmatically,then you know the answer for my question.Thank you :) – Ivelius Jan 10 '12 at 08:22
  • Did you ever find a solution to your problem? Either by actually triggering a "paste" event or do something else? I have the same problem here. – freeall Sep 19 '12 at 11:54

1 Answers1

2

Try using document.createEvent and the necessary arguments to imitate the "paste" action (e.g. CTRL-V).

There is likely also a "paste" event which can be created and dispatched but browser support may (will!) vary.

groovecoder
  • 1,551
  • 1
  • 17
  • 27
maerics
  • 151,642
  • 46
  • 269
  • 291
  • That's more like it ! :) I successfully dispatched a "click" event,but still no luck with the "key press event" :( Here you can see my code http://pastie.org/3159158 .This is a sample page.I'm trying to simulate CTRL-V here so that whatever is in the clipboard now will be pasted into a text area. But I can't understand why it doesn't work :( – Ivelius Jan 10 '12 at 09:09