Reputation: 4619
I have the following code which works quite well with browser when the user is closing the tab.
//Alert if quitting
safeExit = false;
function closeEditorWarning(){
if(!safeExit){
return 'Please remember to save and sync your changes'
}
safeExit = false;
}
window.onbeforeunload = closeEditorWarning;
We have previously tested this using the simple demo in CEF3, however it doesnt seem to execute when we ported the app to Node-webkit. Any help would be appreciated.
Upvotes: 2
Views: 1667
Reputation: 5751
You should wrap your call in a "on" event on the window.
safeExit = false;
win.on('close', function () {
// show warning if you want
this.close(safeExit);
});
Warning - the above code will go into an infinite loop, you can simply open the console and set safeExit to true to exit the program. I hope this helps!
Upvotes: 3