fire a “paste” event in Javascript

2019-04-08 22:42发布

问题:

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.

回答1:

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.