Specifically, I want to copy a link (with text and location) and then to be able to paste it, e.g., into Word as a link.
views:
654answers:
2
+2
A:
dig around inside Download of the Day: AutoCopy Firefox extension or Clipboard-Save-As 1.0.4
boost
2008-10-20 15:34:43
Thanks, I'll try. Meanwhile, you've a typo in the second link. It should be https://addons.mozilla.org/en-US/firefox/addon/1478
Lev
2008-10-20 16:09:28
AutoCopy does the trick
Lev
2008-10-20 16:24:31
fixed the link. Thanks for the heads-up.
boost
2008-10-21 03:14:50
+2
A:
Here's the actual code:
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);
It is also recommended to create another Components.interfaces.nsISupportsString
, whose data is plain text, and add it to the same xfer
as text/unicode
Lev
2008-10-20 17:26:09