简体   繁体   中英

What is more appropriate to identify a window opened via menu, outerWindowID or currentInnerWindowID?

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.

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.

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.

在此输入图像描述

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM