Skip to content

Instantly share code, notes, and snippets.

@suziwen
Created March 8, 2017 15:37
Show Gist options
  • Save suziwen/9e8f4b24f63e22ab7f0292ac02386619 to your computer and use it in GitHub Desktop.
Save suziwen/9e8f4b24f63e22ab7f0292ac02386619 to your computer and use it in GitHub Desktop.
nw.js `nw.Window.get()` return incorret window object
<!DOCTYPE html>
<html lang="en">
<head>
<title>example</title>
</head>
<body >
<div>iframe content
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>example</title>
</head>
<body onload="init()">
<div>
<div>
<button id="getIframeWindow" value="">getIframeWindow</button>
</div>
<iframe src="iframe.html" id="iframe" frameborder="0"></iframe>
</div>
<script type="text/javascript">
function init(){
var win = nw.Window.get();
win.maximize();
var iBtn = document.getElementById('getIframeWindow');
iBtn.onclick = function(){
var _iframe = document.getElementById('iframe');
var cw = _iframe.contentWindow;
_pw = nw.Window.get();
_pww = _pw.window;
_pwwd = _pw.window.document;
_cw = nw.Window.get(cw);
_cww = _cw.window;
_cwwd = _cw.window.document;
console.log(_pw === _cw);
console.log(_pww === _cww);
console.log(_pwwd === _cwwd);
// from right now , `nw.Window.get()` return incorret window obj
_newpw = nw.Window.get();
_newpww = _newpw.window;
_newpwwd = _newpww.document;
console.log(_pw === _newpw);
console.log(_pww === _newpww); // expect true ,but false
console.log(_pwwd === _newpwwd); // expect true ,but false
_new1pw = nw.Window.get(_pww);
_new1pww = _new1pw.window;
_new1pwwd = _new1pww.document;
console.log(_pw === _new1pw);
console.log(_pww === _new1pww); // expect true ,but false
console.log(_pwwd === _new1pwwd); // expect true ,but false
}
}
</script>
</body>
</html>
{
"main": "index.html",
"name": "test",
"description": "test",
"version": "1.0.0",
"keywords": [ "test" ],
"window": {
"title": "test",
"frame": true,
"width": 400,
"height": 200,
"position": "center",
"resizable": true,
"show": true,
"min_width": 400,
"min_height": 200
},
"webkit": {
"plugin": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment