1

There are certain configuration files that the user should save before closing the browser. Is there a way to detect if the user is trying to close the browser and to warn them to first save the files?

jadrijan
  • 1,438
  • 4
  • 31
  • 48

3 Answers3

1

You should define a public method inside your applet and invoke it using Javascript before the user closes a page: window.onbeforeunload = document.YourApplet.YourMethod(event); where YourApplet is your applet's name attribute: <applet name="YourApplet" ... and YourMethod is the method you defined in your applet.

Nick Shvelidze
  • 1,564
  • 1
  • 14
  • 28
1

You can use javascript to detect this. And you can invoke applet methods from javascript.

So you should define a javascript onunload handler which invokes your applet's close method.

Community
  • 1
  • 1
ewan.chalmers
  • 16,145
  • 43
  • 60
1

Generally the PlugIn will try to stop the applet once the browser window (or just tab) closes or navigates elsewhere.

IIRC, you used to get 20 seconds to do your clear up before the PlugIn started getting medieval. I believe if there are no other applets sharing the JVM, the process will now get killed if you don't stop.

So, you really don't want to be hanging around attempting to show annoying save dialogs. I would go so far as to say, you don't want annoying save dialogs. So just do the saves quietly. Add a "you didn't save, do you want to restore these changes" thing (like the re-open windows dialogette beneath the toolbar in Chrome) when restarting. For extra marks, log deltas periodically in the background, so that even in the case of abrupt termination or network failure the data can be restored.

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305