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.
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.
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);
}
© 2022 - 2024 — McMap. All rights reserved.