Skip to content

Commit 963f132

Browse files
xzhan96rogerwang
authored andcommitted
Correct the function of Window.get inconformity with the original design
iframe's window should not have independent Window object fixed nwjs#5043, nwjs#5044, nwjs#5755
1 parent c3e818f commit 963f132

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/References/Window.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
[TOC]
55

6-
`Window` is a wrapper of the DOM's `window` object. It has extended operations and can receive various window events.
6+
`Window` is a wrapper of the DOM's topmost `window` object. It has extended operations and can receive various window events.
77

88
Every `Window` is an instance of the EventEmitter class, and you're able to use `Window.on(...)` to respond to native window's events.
99

10+
!!! warning "Behavior Changed"
11+
There are some changes of `Window` since 0.13.0. Please see [Migration Notes from 0.12 to 0.13](../For Users/Migration/From 0.12 to 0.13.md).
12+
1013
## Synopsis
1114

1215
```javascript
@@ -41,10 +44,19 @@ nw.Window.open('https://github.com', {}, function(new_win) {
4144

4245
If `window_object` is not specifed, then return current window's `Window` object, otherwise return `window_object`'s `Window` object.
4346

47+
!!! note
48+
If `window_object` is `iframe`'s, the function will still return topmost window's `Window` object.
49+
4450
```javascript
4551
// Get the current window
4652
var win = nw.Window.get();
4753

54+
// Get iframe's window
55+
var iframeWin = nw.Window.get(iframe.contentWindow);
56+
57+
//This will return true
58+
console.log(iframeWin === win);
59+
4860
// Create a new window and get it
4961
nw.Window.open('https://github.com/nwjs/nw.js', {}, function(new_win) {
5062
// do something with the newly created window

src/resources/api_nw_window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
170170
var apiFunctions = bindingsAPI.apiFunctions;
171171
apiFunctions.setHandleRequest('get', function(domWindow) {
172172
if (domWindow)
173-
return try_nw(domWindow).nw.Window.get();
173+
return try_nw(domWindow.top).nw.Window.get();
174174
if (currentNWWindow)
175175
return currentNWWindow.outerWindow;
176176

0 commit comments

Comments
 (0)