Skip to content

Commit

Permalink
Correct the function of Window.get inconformity with the original design
Browse files Browse the repository at this point in the history
iframe's window should not have independent Window object

fixed nwjs#5043, nwjs#5044, nwjs#5755
  • Loading branch information
xzhan96 committed Mar 21, 2017
1 parent 3ea65f9 commit a53cae4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion docs/References/Window.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

[TOC]

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

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

!!! warning "Behavior Changed"
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).

## Synopsis

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

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

!!! note
If `window_object` is `iframe`'s, the function will still return topmost window's `Window` object.

```javascript
// Get the current window
var win = nw.Window.get();

// Get iframe's window
var iframeWin = nw.Window.get(iframe.contentWindow);

//This will return true
console.log(iframeWin === win);

// Create a new window and get it
nw.Window.open('https://github.com/nwjs/nw.js', {}, function(new_win) {
// do something with the newly created window
Expand Down
2 changes: 1 addition & 1 deletion src/resources/api_nw_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
apiFunctions.setHandleRequest('get', function(domWindow) {
if (domWindow)
return try_nw(domWindow).nw.Window.get();
return try_nw(domWindow.top).nw.Window.get();
if (currentNWWindow)
return currentNWWindow.outerWindow;

Expand Down

0 comments on commit a53cae4

Please sign in to comment.