Safari浏览器不支持document

Safari浏览器不支持document

本文介绍了Safari浏览器不支持document.execCommand('copy');命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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');
}

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

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

推荐答案

此时, execCommand('copy ') Safari不支持API,但在Safari 10中会更改:

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

这篇关于Safari浏览器不支持document.execCommand('copy');命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 09:46