在firefox扩展程序中,如何枚举当前窗口的选项卡并检索其URL?
There's a code snippet at MDC that does exactly that:
var num = gBrowser.browsers.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);
}
}
When using Firefox SDK, see this:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/List_Open_Tabs
var tabs = require("sdk/tabs");
for (let tab of tabs)
console.log(tab.url);
Additionally, the tabs
object seems to have array interface, so you can use also the .length
property:
var tabs = require("sdk/tabs");
for (var i = 0; i < tabs.length; i++)
console.log(tabs[i].url);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.