2008-10-20 71 views

回答

6

下面是實際的代碼:

var richText = "<a href=\"" + gContextMenu.linkURL + "\">" + gContextMenu.linkText() + "</a>"; 
var xfer = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); 
xfer.addDataFlavor("text/html"); 

var htmlString = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
htmlString.data = richText; 
xfer.setTransferData("text/html", htmlString, richText.length * 2); 

var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard); 
clipboard.setData(xfer, null, Components.interfaces.nsIClipboard.kGlobalClipboard); 

此外,還建議創建另一個Components.interfaces.nsISupportsString,其數據是純文本,並將其添加到同一xfertext/unicode

相關問題