Skip to content

opener in windows opened by NW API always points to top frame #3431

Open
@ghostoy

Description

@ghostoy

You can reproduce the issue with following test case.

In top frame, you will see windows opened by window.open() or nwGui.Window.open() will set top frame to red. That's expected because they are opened by top frame.

In child frame (just click create frame button to create it), windows opened by window.open() will get correct child frame set to red. But windows opened by nwGui.Window.open() will get top frame set to red. That's not expected.


index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>index.html</title>
</head>
<body>
  <button onclick="openWin()">window.open()</button>
  <button onclick="openWinNW()">gui.Window.open()</button>
  <button onclick="createFrame()">create a frame</button>
  <script>

  function hello() {
    document.body.style.backgroundColor = 'red';
    setTimeout(function() {
      document.body.style.backgroundColor = 'white';
    }, 2000);
  }

  function openWin() {
    window.open('child.html', '_blank', 'width=200,height=200');
  }

  function openWinNW() {
    require('nw.gui').Window.open('child.html', {width:200,height:200});
  }

  function createFrame() {
    var frame = document.createElement('iframe');
    frame.src='index.html';
    frame.style.styleText = 'width:600px;height:600px;';
    document.body.appendChild(frame);
  }
  </script>
</body>
</html>

child.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>child</title>
</head>
<body onload="callHello()">
  <script>
  function callHello() {
    window.opener.hello();
    window.close();
  }
  </script>
</body>
</html>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions