识别通过菜单打开的窗口、outerWindowID 或 currentInnerWindowID 哪个更合适?

发布于 2024-12-20 13:45:11 字数 860 浏览 2 评论 0原文

我需要识别通过菜单打开的窗口: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

·深蓝 2024-12-27 13:45:11

通常您需要内部窗口的 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.

单身狗的梦 2024-12-27 13:45:11

以下是内部和外部窗口(MDN 文章)的摘录:

<块引用>

外部窗口是一个浏览上下文;也就是说,实际的
将文档呈现给用户的环境。这可能是
一个窗口选项卡,或者它可能是包含在其中的iframe
另一份文件。 HTML5 将外部窗口称为 WindowProxy。

内部窗口代表实际显示的内容;
这是用户所看到内容的当前视图。

在此处输入图像描述

当用户导航时,文档将添加到前后视图中
缓存(通常称为 bfcache)。这些本质上都是内在的
视窗。它们显示在外部窗口中,该窗口包含在
“物理”浏览器窗口。

因此,当我想识别通过菜单打开的具有“物理”存在的窗口时,我应该使用 outerWindowID

Here an extract of Inner and outer windows (MDN article):

An outer window is a browsing context; that is, the actual
environment in which a Document is presented to the user. This may be
a window or a tab, or it might be an iframe contained within
another document. HTML5 refers to the outer window as the WindowProxy.

An inner window represents the actual content being displayed;
it's the current view of what the user sees.

enter image description here

As the user navigates, documents are added to the backward-forward
cache (often referred to as the bfcache). These are, in essence, inner
windows. They get displayed in the outer window, which is contained in
the "physical" browser window.

So as I want identify windows opened via menu that have a "physical" presence I should use outerWindowID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文