将文本复制到剪贴板的最佳方法是什么?(多浏览器)
我试过了:
function copyToClipboard(text) {
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData("Text", text);
} else {
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
Run Code Online (Sandbox Code Playgroud)
但在Internet Explorer中,它会出现语法错误.在Firefox中,它说unsafeWindow is not defined.
没有闪存的好技巧:Trello如何访问用户的剪贴板?
如何将div中的文本复制到剪贴板?我有一个div,需要添加一个链接,将文本添加到剪贴板.这有解决方案吗?
<p class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
<a class="copy-text">copy Text</a>
Run Code Online (Sandbox Code Playgroud)
单击复制文本后,我按Ctrl+ V,必须粘贴.
随着闪存在许多环境(iPhone,Android,IE10等)的出路上,有没有任何新的解决方案即将在没有安装闪存的情况下安全地将信息复制到剪贴板?
到目前为止我一直在使用ZeroClipboard,但是我担心更多没有闪存的观众,这个功能会被破坏,我希望尽可能不依赖于Flash.