david
david

Reputation: 4278

check if new window is still open

Ive been reading the node-webkit wiki and may have missed or just dont understand from the documentation, so i have been trying lots of ways which i think is how one would check to see if a new window is open or not,

One way im checkig is storing the 'new_win' var in "on('loaded')" and "on('close')".

I would like to know if what i am doing is ok, or whats an more efficent way.

var new_win;

function openPopUp(){


if(new_win){
  console.log("New win was already opened");
}else{
  console.log("Opened a new window");
}

var gui = require('nw.gui');

new_win = gui.Window.open('popup_page.html', {});


new_win.on('loaded', function(){
new_win = true
});

new_win.on('close', function() {
this.close(true);
new_win = false
});

}

Upvotes: 2

Views: 650

Answers (1)

Roger Wang
Roger Wang

Reputation: 1376

Currently there is a trick to do this: An exception will be thrown on accessing to Win.window after it's closed.

Upvotes: 2

Related Questions