简体   繁体   English

无法使document.execCommand与复制文本一起正常工作

[英]cannot get document.execCommand to work properly with copying text

Here is my code: 这是我的代码:

function createTextArea() {
    var t = document.createElement("textArea");
    textArea = document.body.appendChild(t);

    return textArea;
}

function copy(str) {
    var textArea = createTextArea();
    textArea.value = str;
    textArea.select();
    document.execCommand("Copy");
}

copy("hello")

Now, when I try to paste, the text I placed into the textarea is not appearing. 现在,当我尝试粘贴时,放置在文本区域中的文本不会出现。 Does anyone know what I'm doing wrong? 有人知道我在做什么错吗?

You have a typo according to documentatin. 根据文档,您有错字。 From Rich-Text Editing in Mozilla about executing commands 来自Mozilla中的Rich Text Editing关于执行命令的信息

copy Copies the current selection to the clipboard. copy将当前选择复制到剪贴板。 Clipboard capability must be enabled in the user.js preference file. must be enableduser.js首选项文件中must be enabled剪贴板功能。

And see those two posts: How do you configure Firefox to allow Javascript to intercept a value pasted from the clipboard? 并查看这两篇文章: 如何配置Firefox以允许Javascript拦截从剪贴板粘贴的值? and Copy to Clipboard for all Browsers using javascript 使用javascript将所有浏览器复制到剪贴板

So, it seems very questionable if you can do that. 因此,是否可以做到这一点似乎很成问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM