【发布时间】:2014-08-25 03:31:31
【问题描述】:
在 javascript Firefox 插件中,请问如何保存指向插件打开的选项卡的指针数组?
最终我希望能够处理每个选项卡上的 DOM,然后关闭选项卡。
我一直在查看 MDN 参考资料,但我无法清楚地了解对象模型。
插件会在标签页中打开多个 URL。
DOMContentLoaded 事件将“选项卡”推送到数组中。
稍后我处理数组中的每个“选项卡”并用它的 DOM 做一些事情。
然后我想关闭标签。
在下面的代码 sn-ps 中,除了关闭标签之外,它似乎都可以工作。
问题:
- 在DOMloadedFunction中,“event.target”到底是什么类型的对象?
- 在 DOMloadedFunction 中,如何为每个函数保留某种“句柄” 新标签,以便我稍后关闭?
代码sn-ps:
var arrPages = [];
//Open the tab
newTabBrowser = gBrowser.getBrowserForTab(gBrowser.addTab(inURL));
newTabBrowser.addEventListener("DOMContentLoaded", DOMloadedFunction, true);
// DOMContentLoaded eventhandler
DOMloadedFunction : function (event)
{
// store the tab
arrPages.push(event.target);
}
// Later the array is processed...
oPage = arrPages.shift();
oPage.contentDocument <-- Do some stuff with DOM object.
// Now close the tab
oPage.close() // this is what I want to do, but I can't figure out how
// Unfortunately the index for gBrowser.mTabs[] seems to change, so
// this code usually closes the wrong tab.
var aTab = gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(oPage)]
aTab.remove();
任何建议表示赞赏,谢谢。
【问题讨论】:
标签: javascript firefox tabs firefox-addon