在开发 Firefox 扩展时,我最终偶然发现能够获取 selectedBrowser< /code>
或 tabbrowser
时,rel="nofollow">selectedTab
。
不知道这两个项目的高级定义(tab
有一个文档?那么为什么 tab
没有浏览器属性?)
同样,我发现自己想知道,如果将属性与用户当前正在执行的操作相关联,我是否最好使用gBrowser.selectedBrowser.MYSPECIALPROPERTY
与 gBrowser.selectedTab.MYSPECIALPROPERTY
。
我通常需要一个浏览器,因为它有我想要使用的方法,而且因为我发现抓取浏览器并使用它们比抓取选项卡和它们更容易,但我不这样做就像在不完全理解原因的情况下偏爱其中一种的想法。
我还发现自己想知道如何从 selectedBrowser
到 selectedTab
或反之亦然,假设这些转换中至少有一个是有意义的。
这些问题在某种程度上是可分离的,但我缺少一些关键的高层理解,所以我不确定我是否能够提出其中一个问题并得到一个消除我困惑的答案。
Working on a firefox extension I eventually hit upon being able to grab a selectedBrowser
or a selectedTab
while using a tabbrowser
.
Not knowing the high level definition of the two items (a tab
has a document? Then why doesn't tab
have a browser property?)
Similarly, I have found myself wondering, if associating properties to what a user is currently doing, if I would be better off using gBrowser.selectedBrowser.MYSPECIALPROPERTY
vs gBrowser.selectedTab.MYSPECIALPROPERTY
.
I usually needed a browser
both because it had the methods I wanted to work with and because I found it easier to grab Browsers and muck with them than to grab Tabs and much with them, but I don't like the idea of prefering one over the other without a full understanding of why.
I would am also found myself wondering how I can get from a selectedBrowser
to a selectedTab
or vice versa, assuming at least one of those transitions even makes sense.
These questions are somewhat separable, but I am missing some key high-level understanding so I'm not sure I'd be able to ask one of these questions and get an answer that cleared up my confusion.
发布评论
评论(1)
是 的专门版本;
。通常,
是选项卡和关联选项卡面板的集合。这里的选项卡实际上是一个选项卡标题,您单击它可以切换到特定选项卡,选项卡面板是随后显示的内容(它是选项卡内容的容器)。选项卡和选项卡面板之间没有直接映射,它们只是碰巧在各自的容器节点中具有相同的索引。至少这是一个稍微复杂的总体想法,因为选项卡可以通过linkedpanel
属性。现在<每个选项卡面板中的 /code>
有一个元素。但它也使用与常规
中相同的
元素。由于
和
都可以在
之外使用,因此您不会在它们上找到任何特殊的 API 。这种 API 仅在
中可用。要获取特定选项卡标题的浏览器,您可以使用
tabbrowser.getBrowserForTab( )
。反之则更复杂(而且通常是不必要的)。如果确实需要,可以使用tabbrowser.getBrowserIndexForDocument()
获取浏览器的索引。然后您可以通过
tabbrowser.tabs.getItemAtIndex()< 获取相应的选项卡/代码>
。
重复一遍:通常您会希望使用
元素。没有理由查看选项卡标题(除非您想对它们重新排序或类似的内容)。A
<tabbrowser>
is a specialized version of<tabbox>
. Normally, a<tabbox>
is a collection of tabs and the associated tab panels. Here the tab is actually a tab header that you click on to switch to a particular tab, the tab panel is what is being displayed then (it's the container for tab content). There is no direct mapping between tabs and tab panels, they simply happen to have the same index in their respective container node. At least that's the general idea that is slightly complicated by the fact that tabs can be linked to a particular panel explicitly vialinkedpanel
attribute.Now a
<tabbrowser>
has a<browser>
element in each of its tab panels. But it uses the same<tab>
elements that you would have in a regular<tabbox>
as well. Since both<tab>
and<browser>
can be used outside of<tabbrowser>
you will not find any special API on them. That kind of API is only available in<tabbrowser>
.To get a browser for a particular tab header you can use
tabbrowser.getBrowserForTab()
. Going the other way round is more complicated (and usually unnecessary). If you really need it, you can usetabbrowser.getBrowserIndexForDocument()
to get the index of the browser. You can then get the corresponding tab viatabbrowser.tabs.getItemAtIndex()
.Just to repeat this: usually you will want to work with the
<browser>
elements. There is little reason to look at tab headers (unless you want to reorder them or something like that).