如何定位Firefox扩展的搜索栏? [英] How do I target the search bar from a Firefox extension?

查看:189
本文介绍了如何定位Firefox扩展的搜索栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的建立扩展 - 并希望知道如何定位Firefox的标准谷歌搜索栏的一些帮助。



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

解决方案

从chrome通常覆盖的chrome://browser/content/browser.xul),您可以通过document.getElementById('searchbar')获得对搜索栏的访问。查找所需id的最佳方法是使用Dom Inspector: a href =https://addons.mozilla.org/en-US/firefox/addon/dom-inspector-6622/ =nofollow> https://addons.mozilla.org/zh-CN/firefox / addon / dom-inspector-6622 /

无论如何,如果你想访问搜索栏的内部dom元素,你需要使用 getAnonymousElementByAttribute ,因为这是匿名的内容(来自XBL绑定)。因此,如果您需要获取输入元素本身(您在输入搜索条件的位置),您可以通过chrome进行如下操作:

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

您需要使用Dom Inspector来确定您需要哪个元素以及如何访问它。

I'm new to building extensions -- and would like some help with knowing how to target the standard Google search bar that comes with Firefox..

I am thinking I have to find out which meni ID it is and assign it somehow within the .xul file..

解决方案

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

Anyhow, if you want to access inner dom elements of the searchbar you'll need to use getAnonymousElementByAttribute because that's anonymous content (from XBL binding). So if you need to get input element itself (where you're typing your search terms) you'll do it something like this from chrome:

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

You'll need to use Dom Inspector to figure out which element you need and how to access it.

这篇关于如何定位Firefox扩展的搜索栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆