具体来说,我想复制一个链接(带有文本和位置),然后能够将其粘贴到例如 Word 中作为链接。
最佳答案
这是实际的代码:
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
,其数据为纯文本,并添加到与text/unicode相同的
xfer
关于firefox - 在 Firefox 扩展中,如何将富文本/链接复制到剪贴板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/218462/