Question

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.

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top