具体来说,我想复制一个链接(带有文本和位置),然后能够将其粘贴到Word中作为链接.
这是实际的代码:
var richText = "" + gContextMenu.linkText() + ""; 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
数据为纯文本的数据,并将其添加到相同的数据xfer
中text/unicode