简体   繁体   English

为什么Cut,Copy,Paste在Mozilla Firefox和Google Chrome浏览器中不起作用?

[英]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.

相关问题 剪贴板(剪切/复制)在Mozilla Firefox浏览器中不起作用 - Clipboard (cut/copy) is not working in Mozilla Firefox browser 为什么我的扩展程序在 Mozilla Firefox 上运行而不是在 Google Chrome 上运行? - Why is my extension working on Mozilla Firefox and not on Google Chrome? Java代码可在Mozilla Firefox中运行,但不能在Google Chrome中运行 - Javascript code working in Mozilla Firefox but not in Google Chrome 网站滑块在Google Chrome和Mozilla firefox上不起作用 - website slider is not working on Google Chrome and Mozilla firefox 在Firefox和Chrome浏览器的CKEditor中禁用了剪切,复制和粘贴功能。 解决方法? - Disabled cut, copy & paste functions in CKEditor with Firefox and Chrome. Workaround? 在chrome和mozilla firefox浏览器中均无法从DhtmlxGrid复制文本 - Not able to copy text from DhtmlxGrid in both chrome and mozilla firefox browser getURL(&quot;javascript:window.close();&quot;) 不适用于当前的网络浏览器,如 firefox mozilla 和 google chrome - getURL("javascript:window.close();") not working in current web browser like firefox mozilla and google chrome 使用Flex 4.6在Mozilla Firefox或Google Chrome上关闭浏览器不起作用 - Closing Browser not work on Mozilla Firefox or Google Chrome using Flex 4.6 table.rows.length在mozilla firefox中不起作用,但在Google Chrome中起作用 - table.rows.length not working in mozilla firefox but working in google chrome 代码块在 mozilla firefox 中工作,但在 Chrome 中不工作 - Code block working in mozilla firefox but not in Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM