How to get text from Address Bar in Firefox extension
Asked Answered
C

2

10

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.

Cragsman answered 21/9, 2010 at 11:32 Comment(4)
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 :)Cragsman
@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.Kettledrummer
@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.Congregational
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 :-)Sheepcote
C
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.

Congregational answered 21/9, 2010 at 23:21 Comment(0)
N
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);
}
Negligent answered 22/9, 2010 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.