dop2000
I did find a solution that worked for me, however, it's a bit of a hassle and involved many steps. In the exported version, they have added a javascript code that overrides any code you add into the editor in regards to preventing the game from closing, which is why it only works in the preview mode. Here's the steps I follow to make this work:
1. Open the exported files folder and find package.nw
2. Change the package.nw file-ending name to .zip instead.
3. Extract the zip file to a new empty folder somewhere on your computer.
4. In that folder where there now are a bunch of files from the extraction, find index.html.
5. Open the file in an editor of choice and scroll down to this section of javascript code:
var win = window['nwgui'].Window.get();
win.on('close', function () {
window['nwgui'].App.quit();
});
The line that you want to remove is the window['nwgui'].App.quit();
However, in doing so, you will need to have a way inside your game to close down the game window so it's not left open after you have run your own code (such as after a "are you sure you want to close?" message). I added a call to a function inside the game as a substitute to the line removed above by using the function "c2_callFunction()".
After that change you need to zip all the extracted files up together again, and then change the .zip file-ending to .nw again, and replace the old package.nw in the original flder with that one.
Hope that helps.