当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: