Reputation: 637
How I can open a new tab in a Firefox add-on with POST variables?
For example, open http://localhost/ with these post variables:
a=NOMADE
b=NOWAY
another=IDONTKNOW
Upvotes: 4
Views: 760
Reputation: 12581
The gBrowser.addTab function is what you want. One of the parameters you pass to that function is postData
, and allows you to set the postData as you would like it. The MDN documentation for that function also points to an article on pre-processing POST data. If I read that second article correctly, the POST data needs to be passed in the form of an nsIInputStream (specifically created as nsIMIMEInputStream). The article provides a sample code snippet for converting from a standard GET style format string (example: foo=1&goo=somestring
) to the intended format.
Edit: So, to use your example, you might do something like this:
var myData = "a=NOMADE&b=NOWAY&another=IDONTKNOW";
// TODO: Translate myData into the nsIMIMEInputStream format using the example
// from the second linked article above
// Add the tab, with the variable data
gBrowser.addTab("http://www.example.com/", {postData: myData});
Upvotes: 4