複製程式碼程式碼如下: 格//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <BR> function test(){<BR> . 🎜>if(window.clipboardData) {<BR> window.clipboardData.clearData();<BR> window.clipboardData.setData("Text", txt);<BR>} else if(navigatorAifgent" Opera") != -1) {<BR>window.location = txt;<BR>} else if (window.netscape) {<BR>嘗試{<BR>netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect ") ;<BR>} catch (e) {<BR>alert("您的firefox安全限制您進行剪貼簿操作,請打開'about:config'將signed.applets.codebase_principal_support'設定為true'之後重試") ;<BR>回傳false;<BR>}<BR>var Clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);<BR> if (! clip)<BR>return;<BR>var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);<BR>if (!trans )<🎜s.nsITransferable);<BR>if (!trans )<BR>return;<BR>trans.addDataFlavor('text/unicode');<BR>var str = new Object();<BR>var len = new Object();<BR>var str = Components. classes[" @mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);<BR>var copytext = txt;<BR>str.data = copytext;<BR>trans.setTransferData(" text/code ",str,copytext.length*2);<BR>var Clipid = Components.interfaces.nsIClipboard;<BR>if (!clip)<BR>return false;<BR>clip.setData(trans,null ,clipid. kGlobalClipboard);<BR>}<BR>}<BR> 複製到貼上板 說明:Firefox 的預設安全性限制不允許透過 JavaScript 複製到剪貼簿,需要提示使用者修改 Firefox 的設定。修改方法是開啟"about:config"將"signed.applets.codebase_principal_support"設為"true"。