如何从 Firefox 扩展中的地址栏获取文本

发布于 2024-09-24 00:23:45 字数 369 浏览 14 评论 0原文

我正在构建一个 Firefox 扩展。我使用 XULJavascript 来执行此操作。我需要从 Firefox 浏览器的地址栏中获取文本。 请不要与浏览器导航的 URL 混淆,它只是用户在页面重定向之前输入的文本。假设用户位于 http://www.myexample.com 或任何页面。现在,他在地址栏中输入 Cricket,一旦按下 Enter 键,我就想从地址栏捕获文本(“Cricket”)。我需要这些数据在我的代码中进一步进行一些处理。

I am building a Firefox Extension. I am using XUL and Javascript to do this. I need to get the text from my Firefox browser's address bar.
Please don't get confused with URL where the browser has navigated, its just the text that user enters before the page redirects. Suppose user is at http://www.myexample.com or whatever page. Now he types Cricket in the Address Bar and as soon as he hits enter, I want to capture the text ("Cricket") from the address bar. I need this data to do some processing further in my code.

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

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

发布评论

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

评论(2

为你拒绝所有暧昧 2024-10-01 00:23:45

正如这个问题的答案所说,这在 Google Chrome 中似乎不可能。

但对于 Firefox,您可以查看此处提到的几个扩展这个并尝试弄清楚他们是如何做到这一点的。我搜索了 MDC 了一下,但没有运气。

我对 Firefox 扩展没有任何经验,所以我希望这对能够给出更准确解释的人有所帮助。

It doesn't seem to be possible in Google Chrome, as answers to this question say.

But with Firefox, you may have a look at several extensions mentioned here or at this one and try to figure out how they did what they did. I searched MDC a bit, but without luck.

I don't have any experience with Firefox extensions, so I hope this will be helpful to someone who can give a more precise explanation.

蓝眼泪 2024-10-01 00:23:45

我认为您需要劫持网址栏的“ontextentered”事件。
我假设您想要即将推出的 Firefox 4,所以请查看:

http://mxr.mozilla.org/mozilla2.0/source/browser/base/content/browser.xul#656

您可以向“urlbar”添加按键监听器" 也可以获取输入的文本。

例如:

document.getElementById("urlbar").setAttribute("ontextentered", "foobar(param);");

function foobar(param) {
       // do somethign w/ param
       // finally call original method if you aren't hijacking the text that was entered
       document.getElementById("urlbar").handleCommand(param);
}

I think you would need to hijack the "ontextentered" event for the url bar.
I'm assuming you'd want Firefox 4 which is around the corner, so look at:

http://mxr.mozilla.org/mozilla2.0/source/browser/base/content/browser.xul#656

You can add a keypress listener to "urlbar" to get text as it is entered as well.

e.g.:

document.getElementById("urlbar").setAttribute("ontextentered", "foobar(param);");

function foobar(param) {
       // do somethign w/ param
       // finally call original method if you aren't hijacking the text that was entered
       document.getElementById("urlbar").handleCommand(param);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文