It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




7年前关闭。




我有获取表ID并将内容复制到剪贴板的功能。该功能在IE中正常运行,但在Chrome或FF中无法正常运行。

请任何人帮忙。谢谢!

function clipBoard(tbID) {
    var div = document.getElementById(tbID);
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
        controlRange = document.body.createControlRange();
        controlRange.addElement(div);
        controlRange.execCommand('Copy');
    }
   div.contentEditable = 'false';
}

最佳答案

Chrome和FF(以及所有其他非IE浏览器)不允许您使用execCommand()复制到剪贴板。

实际上,由于存在允许任意访问剪贴板的安全问题,因此没有用于复制到剪贴板的单一跨​​平台方法。

一些站点通过使用基于Flash的zeroclipboard来解决此问题。

10-06 15:13