[英]why Cut,Copy,Paste is not working in Mozilla Firefox and Google Chrome browser?
I tried to create a RichText Editor using jQuery with the help of execCommand(). 我尝试在execCommand()的帮助下使用jQuery创建RichText Editor。
But the following code: 但是以下代码:
document.execCommand('cut', false, null);
document.execCommand('copy', false, null);
document.execCommand('paste', false, null);
Is not working in Mozilla Firefox, Google Chrome and some other browsers. 不适用于Mozilla Firefox,Google Chrome和其他一些浏览器。
Are there any possibilities to do the Cut, Copy and Paste actions using execCommand() or there is any other method to do the Cut, Copy and Paste actions in my RichText Editor? 是否有可能使用execCommand()执行剪切,复制和粘贴操作,或者还有其他方法可以在我的RichText编辑器中执行剪切,复制和粘贴操作?
It's easy to solve this problem, follow these steps: Go to "about:config" no quotes on Firefox and then hit the "i'll be careful, I promise" button, next type "dom.event.clipboardevents.enabled" then double click it, so the value is false. 解决这个问题很容易,请按照以下步骤操作:在Firefox上转到“about:config”没有引号,然后点击“我会小心,我保证”按钮,然后输入“dom.event.clipboardevents.enabled”然后双击它,因此值为false。 And that should do the trick.
这应该可以解决问题。
From Chrome 42 and Firefox 41, document.execCommand('cut') and document.execCommand('copy') will work, but only on semi trusted events. 从Chrome 42和Firefox 41, document.execCommand('cut')和document.execCommand('copy')将起作用,但仅适用于半可信事件。 See here https://www.w3.org/TR/2014/WD-clipboard-apis-20140313/#semi-trusted-events
请参见https://www.w3.org/TR/2014/WD-clipboard-apis-20140313/#semi-trusted-events
Like this for example: 像这样例如:
document.getElementById('copy').onmousedown = function() { console.log(document.execCommand('copy')) } document.getElementById('cut').onmousedown = function() { console.log(document.execCommand('cut')) }
<textarea></textarea> <button id="copy">Copy</button> <button id="cut">Cut</button>
On Chrome document.execCommand('paste') will work the same way but requires an extension to be installed to allow it. 在Chrome上, document.execCommand('paste')将以相同的方式工作,但需要安装扩展才能允许它。 Without extension, it won't work.
没有扩展,它将无法工作。 To allow it, you need to include this "clipboarRead" in the permissions in your manifest.json file.
要允许它,您需要在manifest.json文件的权限中包含此“clipboarRead” 。 Like this:
像这样:
permissions: {
...
"clipboardRead"
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.