views:

264

answers:

1

Hi,

How do I detect when user closes(navigates away) or refreshes web page with JavaFX applet in it. I want to do some clean up in my code on those events. Java Applet had some callback methods to do that, but how would I do it in JavaFX running in browser?

Thanks,

+1  A: 

Two steps:

  1. You may need to use a Javascript's window.onunload event to tell your JavaFX app to "close". If you do this, you can then
  2. Add FX.addShutdownAction(myfunction); to your run() function. This will execute myfunction when your app is closed.

I don't have some complete code for you here, but I hope it's a start. You may not need to do step 1.

Eric Wendelin
Yes, I did something similar. Added javascript window.onbeforeunload = onClose; into html page and added function onClose() : Void {...} function into loose code portion of the javaFX script.
Ma99uS