What is the best way to copy text to the clipboard? 将文本复制到剪贴板的最佳方法是什么? (multi-browser) (多浏览器) 浏览器
I have tried: 我试过了: spa
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); } }
but in Internet Explorer it gives a syntax error. 可是在Internet Explorer中,它会给出语法错误。 In Firefox, it says unsafeWindow is not defined
. 在Firefox中,它说unsafeWindow is not defined
。 .net
A nice trick without flash: How does Trello access the user's clipboard? 一个没有闪光灯的好技巧: Trello如何访问用户的剪贴板? code