did you check this way .
With node js and window ?
https://github.com/nwjs/nw.js/wiki/window
close
The close event is a special event that will affect the result of the Window.close() function. If developer is listening to the close event of a window, the Window.close() call to that window will not close the window but send the close event.
Usually you would do some shutdown work in the callback of close event, and then call this.close(true) to really close the window, which will not be caught again. Forgetting to add true when calling this.close() in the callback will result in infinite loop.
And if the shutdown work takes some time, users may feel that the app is exiting slowly, which is bad experience, so you could just hide the window in the close event before really closing it to make a smooth user experience.
For use case you can see demo code of Window.close() above.
Since v0.8.4 on OSX, there is a parameter on the callback of this event. Its value will be set to 'quit' if the window is being closed by pressing 'Cmd-Q' (intent to quit application). Otherwise the value is undefined. See
https://github.com/rogerwang/node-webkit/issues/430
closed
The closed event is emitted after corresponding window is closed. Normally you'll not be able to get this event since after the window is closed all js objects will be released. But it's useful if you're listening this window's events in another window, whose objects will not be released.
PHP:
var gui = require('nw.gui');
// Open a new window.
var win = gui.Window.open('popup.html');
// Release the 'win' object here after the new window is closed.
win.on('closed', function() {
win = null;
});
// Listen to main window's close event
gui.Window.get().on('close', function() {
// Hide the window to give user the feeling of closing immediately
this.hide();
// If the new window is still open then close it.
if (win != null)
win.close(true);
// After closing the new window, close the main window.
this.close(true);
});
Also this is work for Chrome but not test with the app .
in the chrome consoleDEV add this. and try close the browser
PHP:
window.onbeforeunload = function (e) {
var message = "Your confirmation message goes here.",
e = e || window.event;
// For IE and Firefox && chrome
if (e) {
e.returnValue = message;
}
// For Safari
return message;
};