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

问题描述 投票:1回答:1

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

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和IE中运行良好,但它在Safari中不起作用。

javascript safari clipboard
1个回答
4
投票

目前,Safari不支持execCommand('copy') API,但这将在Safari 10中更改:https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html

© www.soinside.com 2019 - 2024. All rights reserved.