如何使用 POST 变量在 Firefox 插件中打开新选项卡?

发布于 2024-12-24 01:54:21 字数 192 浏览 0 评论 0原文

如何使用 POST 变量在 Firefox 插件中打开新选项卡?

例如,使用以下 post 变量打开 http://localhost/

a=NOMADE
b=NOWAY
another=IDONTKNOW

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清引 2024-12-31 01:54:21

gBrowser.addTab 函数就是您想要的。您传递给该函数的参数之一是 postData,它允许您根据需要设置 postData。该函数的 MDN 文档还指向一篇关于预处理 POST 数据的文章 。如果我正确地阅读了第二篇文章,则 POST 数据需要以 nsIInputStream 的形式传递(具体创建为 nsIMIMEInputStream)。本文提供了一个示例代码片段,用于从标准 GET 样式格式字符串(例如:foo=1&goo=somestring)转换为预期格式。

编辑:因此,要使用您的示例,您可以执行以下操作:

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});

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});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文