任何在javascript中捕获上下文菜单“粘贴”的方法

Any way to catch a contextmenu "Paste" in javascript?

本文关键字:粘贴 方法 菜单 上下文 javascript 任何      更新时间:2023-09-26

我需要将一些操作附加到您在之前复制一些文本时浏览器弹出的菜单中的"粘贴"菜单项,然后右键单击某些输入字段。除了实现自己的整个菜单并将其附加到上下文菜单事件之外,还有什么方法可以做到这一点?

我相信你能得到的最接近的是在Javascript中使用onpaste事件。

它捕获上下文菜单的Paste以及Ctrl + V关键事件。

下面是一个演示:

document.getElementById("textbox").onpaste = function(){
  alert("trying to paste something, huh?");
  // do something more
}
document.getElementById("textbox").ondrop = function(){ // user may also try to get the text in the textbox by dragging and dropping
  alert("trying to drag-drop something, huh?");
  // do something more
}
<input type="text" value="paste something here" id="textbox" />

粘贴文档 |多核