【问题标题】:cannot get document.execCommand to work properly with copying text无法让 document.execCommand 与复制文本一起正常工作
【发布时间】:2013-12-08 21:09:17
【问题描述】:

这是我的代码:

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")

现在,当我尝试粘贴时,我放入 textarea 的文本没有出现。有谁知道我做错了什么?

【问题讨论】:

    标签: javascript browser copy-paste


    【解决方案1】:

    根据文档,您有一个错字。来自Rich-Text Editing in Mozilla关于执行命令

    copy 将当前选择复制到剪贴板。 user.js 首选项文件中的剪贴板功能 must be enabled

    看看这两个帖子: How do you configure Firefox to allow Javascript to intercept a value pasted from the clipboard?Copy to Clipboard for all Browsers using javascript

    所以,你是否能做到这一点似乎很值得怀疑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-07
      • 2021-09-24
      • 2019-10-31
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多