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