识别通过菜单打开的窗口、outerWindowID 或 currentInnerWindowID 哪个更合适?
我需要识别通过菜单打开的窗口: File > Firefox 浏览器中的新窗口
。 MDN 为我们提供了唯一标识 DOM 窗口的解决方案。基本上:
var util = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var windowID1 = util.outerWindowID;
var windowID2 = util.currentInnerWindowID;
alert("outerWindowID: \t\t\t" + windowID1 + "\ncurrentInnerWindowID: \t" + windowID2);
研究接口定义:
currentInnerWindowID:窗口当前内部窗口的ID。 只读。
outerWindowID:窗口的外部窗口的ID。读 仅。
很清楚,但我仍然无法决定哪个更适合识别通过菜单打开的窗口。
I need identify windows that are opened via menu: File > New window
in the firefox browser. MDN give us a solution in Uniquely identifying DOM windows. Basically:
var util = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var windowID1 = util.outerWindowID;
var windowID2 = util.currentInnerWindowID;
alert("outerWindowID: \t\t\t" + windowID1 + "\ncurrentInnerWindowID: \t" + windowID2);
Investigating the interface definition:
currentInnerWindowID: The ID of the window's current inner window.
Read only.
outerWindowID: The ID of the window's outer window. Read
only.
Pretty clear but still I can't decide which is more appropriate to identify a window opened via menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常您需要内部窗口的 ID - 这就是您通常使用的。外部窗口是一个支持快退/快进的结构,并且可以由多个内部窗口共享视窗。我不知道为什么它可以被 JavaScript 访问。
Normally you want the ID of the inner window - that's what you usually work with. The outer window is a construction to support fast back/forward and can be shared by multiple inner windows. I'm not sure why it was even made accessible to JavaScript.
以下是内部和外部窗口(MDN 文章)的摘录:
因此,当我想识别通过菜单打开的具有“物理”存在的窗口时,我应该使用 outerWindowID。
Here an extract of Inner and outer windows (MDN article):
So as I want identify windows opened via menu that have a "physical" presence I should use outerWindowID.