您能否指导我如何解决以下问题,或建议复制到剪贴板的其他选项?
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中不起作用。
目前,Safari不支持execCommand('copy')
API,但这将在Safari 10中更改:https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html