如何从 Firefox 扩展中的地址栏获取文本
我正在构建一个 Firefox 扩展。我使用 XUL 和 Javascript 来执行此操作。我需要从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如这个问题的答案所说,这在 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.
我认为您需要劫持网址栏的“ontextentered”事件。
我假设您想要即将推出的 Firefox 4,所以请查看:
http://mxr.mozilla.org/mozilla2.0/source/browser/base/content/browser.xul#656
您可以向“urlbar”添加按键监听器" 也可以获取输入的文本。
例如:
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.: