MozillaZine

Enumerating tabbrowser tabs

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 21:15, 5 February 2007
Np (Talk | contribs)
(down a level)
<-- Previous diff
Revision as of 23:47, 5 February 2007
Grimholtz (Talk | contribs)
(moved to MDC)
Next diff -->
Line 1: Line 1:
{{extdev}} {{extdev}}
-<ul><li>To go through all open tabs in a browser, you first need to get a reference to browser's window. If your code is executed from a <code>browser.xul</code> (in Firefox) overlay (for example it is a toolbar button or menu ''click'' handler), you can access current window via <code>window</code> pre-defined variable. 
-If your code is executed from its own window (for example, Settings dialog), you can use <code>[http://developer.mozilla.org/en/docs/nsIWindowMediator nsIWindowMediator]</code> to get it.</li>+Moved to [[http://developer.mozilla.org/en/docs/Code_snippets:Tabbed_browser#Enumerating_tabs MDC]]
- +
-<li>Then you need to get the <code><tabbrowser></code> element. You can get it with <code>win.gBrowser</code>, where <code>win</code> is the browser's window from the previous step. You can use just <code>gBrowser</code> instead of <code>window.gBrowser</code>, if running from <code>browser.xul</code> overlay.</li>+
- +
-<li>Now use <code>gBrowser.mPanelContainer.childNodes.length</code> to get the number of open tabs. Then use <code>gBrowser.getBrowserAtIndex()</code> to get a <code><browser></code> element. For example:+
-<pre>var num = gBrowser.mPanelContainer.childNodes.length;+
-for(var i = 0; i < num; i++) {+
- var b = gBrowser.getBrowserAtIndex(i);+
- try {+
- dump(b.currentURI.spec); // dump URLs of all open tabs to console+
- } catch(e) {+
- Components.utils.reportError(e);+
- }+
-}</pre>+
-</li>+
-</ul>+
- +
-To learn what methods are available for <code><browser></code> and <code><tabbrowser></code> elements, use [[DOM Inspector]] or look in [http://lxr.mozilla.org/seamonkey/source/toolkit/content/widgets/browser.xml browser.xml] and [http://lxr.mozilla.org/seamonkey/source/toolkit/content/widgets/tabbrowser.xml tabbrowser.xml] for corresponding [[Development resources#XBL|XBL]] bindings.+
[[Category:Example code]] [[Category:Example code]]

Revision as of 23:47, 5 February 2007

This page is part of the extension development documentation project.

Ask your questions in MozillaZine Forums. Also try browsing example code.

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).


Moved to [MDC]