在 Javascript 中触发“粘贴”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8789975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:35:10  来源:igfitidea点击:

fire a "paste" event in Javascript

javascripteventspaste

提问by Ivelius

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.

为什么我需要那个?好吧,当您将链接复制到 Facebook 中的消息文本区域时,您会看到自动调用的 ajax 脚本会更改页面,以便收件人可以看到除了链接之外的附加图像。

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.

因为我不打算使用 Facebook API 之类的东西,所以我只想调用 paste 事件,希望能触发我需要的脚本。

回答by maerics

Try using document.createEventand the necessary argumentsto imitate the "paste" action (e.g. CTRL-V).

尝试使用document.createEvent必要的参数来模仿“粘贴”操作(例如CTRL-V)。

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

可能还有一个“粘贴”事件可以创建和调度,但浏览器支持可能(将!)有所不同。