javascript - window.opener not set after a gui.Window.open() -
i'm building app node-webkit , experiencing trouble opening new window.
basically happens in app :
open splash.html ( splash screen )
- open main application ( main.html) gui.window.open() hide
- on 'loaded' event, close first window ( splash.html ) , show main.html
in app can compose email creates new window ( composer.html )
- user click compose button -> open composer gui.window.open()
the compose window rely on main window it's logic, main window accessed window.opener
this works fine using regular browser, when bundle inside node-webkit, window.opener undefined. because ( ~10% ) opener set in compose window. tried figure out wrong googling on subject didn't helped me.
the things tried :
- setting window opener current window after opening => fail
- going down first opened window ( 1 defined in package.json ) call open() => fail
if has hints on how solve this, appreciated. i'll happy give more details if required.
[edit]
here relevant code :
first window ( splash screen ), opened package.json
<html> <script> var gui = require('nw.gui'); var config = require('./config.json'); gui.app.clearcache(); var nwwin = gui.window var appwin = nwwin.open(config.url, { title : 'myapp', show : false, toolbar : false, frame : false, icon : 'favicon.png', width : 1000, height : 600, min_width : 1000, min_height : 400, position : 'center' }); appwin.on('loaded', function () { appwin.show(); appwin.focus(); appwin.setalwaysontop(true); appwin.setalwaysontop(false); nwwin.get().close(); }) </script> <body> <img src="logo.png" /> </body> </html>
lots of things in application here code open email composer :
nwdesktop.prototype.openappwindow = function (type, url, title) { var appwin = nwwin.open(url, { position: 'center', toolbar: false, frame: true, title: title, icon: 'favicon.png' }); };
in opened window, window.opener = undefined.
you need change little thing:
first in splash screen:
appwin.on('loaded', function () { appwin.show(); appwin.focus(); appwin.setalwaysontop(true); appwin.setalwaysontop(false); nwwin.get().hide(); })
now, window.opener not null or undefined , can make wherever want.
other things make listener appwin windows events so, kill main process of nw when user close windows.
like this:
appwin.on('close',function(){ console.log('close'); gui.app.quit(); });
hope helps.
Comments
Post a Comment