How do I target the search bar from a Firefox extension?

I'm new to building extensions - and I'd like to help with understanding how to target the default Google search bar that ships with Firefox.

I think I need to figure out what the Menintian ID is and assign it somehow in the .xul file.

+1


source to share


1 answer


From chrome (usually the chrome overlay: //browser/content/browser.xul) you can access the search bar by getting it with document.getElementById ('searchbar'). The best way to find the IDs you want is with Dom Inspector: https://addons.mozilla.org/en-US/firefox/addon/dom-inspector-6622/

Anyway, if you want to access the inner dom elements in the search bar, you will need to use getAnonymousElementByAttribute as this is anonymous content (from XBL) So if you need to get the input element itself (where you type the search terms), you would do something like this from chrome:



var searchbarElement = document.getElementById('searchbar');
var input = document.getAnonymousElementByAttribute(searchbarElement, 'anonid', 'input');

      

You will need to use the Dom Inspector to figure out which item you need and how to get it.

0


source







All Articles