Firefox插件-如何关闭标签打开后,他们
Firefox addon - how to close tabs after opening them?
在一个javascript Firefox插件,请我如何保持一个指针的选项卡数组的插件打开?
最终,我希望能够处理每个选项卡上的DOM,然后关闭选项卡。
我一直在看MDN参考,但我不能在我的头脑中得到一个清晰的图像的对象模型。
该插件在选项卡中打开了许多url。
DOMContentLoaded事件将"tabs"推入数组。
之后,我处理数组中的每个"tab",并对它的DOM做一些事情。
然后我想关闭选项卡。
在下面的代码片段中,除了关闭选项卡之外,似乎都可以正常工作。
问题:
- 在domloaddfunction中,什么类型的对象是"事件"?目标"?
- 在domloaddfunction中,我如何保持某种"句柄"到每个新选项卡,这样我可以稍后关闭它?
代码片段:
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();
试试这个,我没有测试它。我也使用getWeakReference
,所以如果你的文档被卸载,它不会在内存中保持打开状态。
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(Cu.getWeakReference(event.target));
}
// Later the array is processed...
oPage = arrPages.shift();
var contDoc = oPage.get();
if (contDoc) { //test if tab is still open
contDoc < --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
var DOMWin = contDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
if (DOMWin.gBrowser) {
if (DOMWin.gBrowser.tabContainer) {
DOMWin.gBrowser.removeTab(DOMWin.gBrowser.getTabForContentWindow(contDoc.defaultView));
} else {
DOMWin.close(); //no tabs probably a popup window of some kind
}
} else {
DOMWin.close(); //close window as its probably a popup window of some kind with no tabs
}
相关文章:
- 检测用户关闭标签页或离开网站
- 提交后打开/关闭潜水标签
- 选项的标签必须在打开和关闭选择时更改
- 在 WebGL 中关闭
- 标签
- 使用 Chrome 的 JavaScript 控制台关闭特定网站的所有标签页
- Chrome 在标签页(或浏览器)关闭时打开卸载前事件
- Facebook如何处理桌面通知的点击,即使我的Facebook标签已关闭
- 不要打开新标签页、关闭标签页或关闭浏览器窗口
- 如何禁用 jQuery 为您关闭 P 标签
- Firefox插件-如何关闭标签打开后,他们
- 检测关闭标签/浏览器没有消息等
- Javascript和PHP一样有打开和关闭标签吗?
- Javascript代码关闭标签,适用于IE, Firefox和Chrome
- 打开和关闭标签在铬与计时器
- 文档的自关闭标签问题.Javascript中的innerHTML
- 关闭按钮关闭标签面板中的活动选项卡,而不是标签按钮附加到EXTJS(标签动态创建)
- 加载新站点时关闭标签页
- jQuery对话框:我如何改变关闭标签的样式
- 字符串处理添加尾斜杠到自关闭标签(IMG, BR等)
- 如何防止关闭标签被移除