复制的事件监听在Firefox中不触发。

huangapple go评论63阅读模式
英文:

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(&#39;divid&#39;);

div.addEventListener(&quot;copy&quot;, () =&gt; {console.log(&quot;copied div&quot;)} );

div.onclick = () =&gt; {console.log(&quot;clicked on div&quot;)}

<!-- language: lang-css -->

#divid {
width: 100px;
background-color: lightblue;
}

<!-- language: lang-html -->

&lt;div id=&#39;divid&#39;&gt;Content of div&lt;/div&gt;

<!-- 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.

huangapple
  • 本文由 发表于 2023年2月27日 08:05:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75575786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定