In the Javascript for a Firefox extension, you can call gBrowser.getBrowserForTab
but there is no gBrowser.getTabForBrowser
. So I wrote my own and it works, and I'm just curious if there's any reason I shouldn't be doing this, or if there's anything wrong with the code. The following is in my init
method that gets called when the window loads.
gBrowser.getTabForBrowser = function(browser) {
for (var i=0; i<gBrowser.browsers.length; i++) {
if (gBrowser.getBrowserAtIndex(i) === browser) {
return gBrowser.tabContainer.getItemAtIndex(i);
}
}
return null;
}
(or should it be gBrowser.prototype.getTabForBrowser = ...
?)