【问题标题】:Safari browser doesn't support document.execCommand('copy'); command?Safari 浏览器不支持 document.execCommand('copy');命令?
【发布时间】:2016-08-15 15:28:45
【问题描述】:

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

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】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 2018-12-20
    • 1970-01-01
    • 2019-07-06
    相关资源
    最近更新 更多