英文:
Copy Eventlistener doesn't fire in Firefox
问题
我为div
设置了一个copy
事件监听器。在Chrome中可以正常工作,但在Firefox中不行。我尝试将oncopy
代替,但没有成功。Google搜索没有提到这个问题。有什么想法是什么问题以及如何解决?
作为示例,下面的代码片段将在Chrome中使用CTRL-C
(或右键单击+复制)显示"copied div",但在Firefox中不会。
谢谢你的帮助。
英文:
I have a copy
eventlistener set up for a div
. It works in Chrome but not in Firefox. I've tried setting oncopy
instead, but without any success. Google search doesn't bring up any mention of this. Any ideas what is the problem and how to fix?
As an example, the below snippet will show "copied div" with CTRL-C
(or right click + copy) in Chrome but not in Firefox.
Thanks for your help.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var div = document.getElementById('divid');
div.addEventListener("copy", () => {console.log("copied div")} );
div.onclick = () => {console.log("clicked on div")}
<!-- language: lang-css -->
#divid {
width: 100px;
background-color: lightblue;
}
<!-- language: lang-html -->
<div id='divid'>Content of div</div>
<!-- end snippet -->
答案1
得分: 1
我不知道下面的Firefox设置是如何被更改/禁用的,但我灵机一动在about:config
中搜索了“clipboard”。
我找到了一个名为dom.event.clipboardevents.enabled
的设置,它被设置为false
。将该值切换为true
解决了问题。
英文:
I don't know how the following Firefox setting got changed / disabled, but I had the inspiration to search within about:config
for "clipboard".
I found a setting for dom.event.clipboardevents.enabled
and it was set to false
. Toggling the value to true
solved the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论