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.
Asked
Active
Viewed 1,955 times
10

animuson
- 53,861
- 28
- 137
- 147

sumit_batcoder
- 3,369
- 1
- 25
- 36
-
Thanks for the help Marcel. I have already checked those links, didn't find what I want here. Please keep posting if you find anything :) – sumit_batcoder Sep 21 '10 at 14:40
-
1@Marcel, that comment really should count as an answer. If you make it an answer, it can be upvoted and this question will be removed from the "unanswered" list, as it should be. – LarsH Sep 21 '10 at 19:22
-
1@LarsH: I'm not convinced, as I only provide a half answer, with a direction that might not lead to success. But I'll make an answer of it, so it's easier to comment on my suggestions. – Marcel Korpel Sep 21 '10 at 23:12
-
I'm new to XUL as well. What I did pick up from a few blogs is that the best thing to do is unjar the browser.jar file and check the browser.xul file. Check the action handlers for the address bar and see how they capture the text. Not much of an answer but hopefully a pointer :-) – Sagar V Sep 22 '10 at 05:15
2 Answers
1
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.

Community
- 1
- 1

Marcel Korpel
- 21,536
- 6
- 60
- 80
0
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);
}

KZ.
- 132
- 2
- 7