Safari浏览器不支持document.execCommand(' copy');命令?

时间:2016-04-22 06:21:56

标签: javascript safari clipboard

您能否指导我如何解决以下问题,或建议另一种复制到剪贴板的选项?

function click_to_copy_password(containerid) {
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(containerid));
        range.select();

    } else if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(document.getElementById(containerid));
        window.getSelection().removeAllRanges();
        window.getSelection().addRange(range);
    }

    document.execCommand('copy');
}

它在Chrome,Firefox和Linux中运行良好IE,但它在Safari中不起作用。

1 个答案:

答案 0 :(得分:4)

目前,Safari不支持execCommand('copy') API,但在Safari 10中会发生变化:https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html