javascript - paste data from clipboard using document.execCommand("paste"); within firefox extension -
i trying paste clipboard info variable gets fed , fired via xmlhttprequest post message.
i have created firefox user.js code increment access clipboard based on recommendation.
user_pref("capability.policy.policynames", "allowclipboard"); user_pref("capability.policy.allowclipboard.sites", "mydomain"); user_pref("capability.policy.allowclipboard.clipboard.cutcopy", "allaccess"); user_pref("capability.policy.allowclipboard.clipboard.paste", "allaccess");
do need alter "mydomain" in line two? not want sites have access. internal firefox extension.
i have read several guides here , here mozilla.
here code have far. clipboard contents should sent post method via xmlhttprequest
. xmlhttprequest
works, have been using other variables.
var pastetext = document.execcommand('paste'); var req = new xmlhttprequest(); req.open('post', pastetext, true); req.onreadystatechange = function(aevt) { if (req.readystate == 4) { if (req.status == 200) dump(req.responsetext); else dump("error loading page\n"); } }; req.send(null);
i grateful help. give thanks you
what need not execcommand
need read info clipboard. addon in privelaged scope don't need worry preferences. (user.js firefox-addon right?)
see here:
mdn :: using clipboard mdn :: nsiclipboardthis way can read contents var pastedcontents
.
here illustration above worked in:
var trans = cc["@mozilla.org/widget/transferable;1"].createinstance(ci.nsitransferable); trans.adddataflavor("text/unicode"); services.clipboard.getdata(trans, services.clipboard.kglobalclipboard); var pastetextnsisupports = {}; var pastetextnsisupportslength = {}; trans.gettransferdata("text/unicode", pastetextnsisupports, pastetextnsisupportslength); var pastetext = pastetextnsisupports.value.queryinterface(ci.nsisupportsstring).data; var req = new xmlhttprequest(); req.open('post', pastetext, true); req.onreadystatechange = function(aevt) { if (req.readystate == 4) { if (req.status == 200) dump(req.responsetext); else dump("error loading page\n"); } }; req.send(null);
javascript firefox firefox-addon clipboard clipboarddata
No comments:
Post a Comment