如何从Firefox扩展中定位搜索栏



我是构建扩展的新手,希望了解如何针对Firefox自带的标准Google搜索栏提供一些帮助。

我想我必须找出它是哪个meni ID,并在。xul文件中以某种方式分配它。

从chrome(通常覆盖的chrome://browser/content/browser.xul),你可以获得访问搜索栏通过获取它与document.getElementById('searchbar')找到你需要的id的最好方法是使用Dom Inspector: https://addons.mozilla.org/en-US/firefox/addon/dom-inspector-6622/

无论如何,如果您想访问搜索栏的内部dom元素,您需要使用getAnonymousElementByAttribute,因为那是匿名内容(来自XBL绑定)。因此,如果你需要得到输入元素本身(你输入你的搜索词)你会这样做,从chrome:

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

你需要使用Dom Inspector来找出你需要的元素以及如何访问它

最新更新