Safari browser doesn't support document.execCommand('copy'); command?

前提是你 提交于 2019-12-06 14:13:56

问题


Can you please guide me on how to fix following issue, or suggest another option for copying to the 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');
}

It's working fine in Chrome, Firefox & IE, but it does not work in Safari.


回答1:


At this moment, the execCommand('copy') API is not supported on Safari but this will change in Safari 10: https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html



来源:https://stackoverflow.com/questions/36786376/safari-browser-doesnt-support-document-execcommandcopy-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!