• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to stop a thread when the user moves away from the JavaFX applet

 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scenario:
A JavaFX applet is loaded and running a thread which populates various UI elements
every 3 seconds Suddenly the user who is viewing the applet decides to open his outlook email
or some other application. At this time, the applet would still be running and updating the UI elements.

I would like to stop the thread. For this, I guess, I need to call some Javascript
function when the user moves out of the tab where the JavaFX applet is currently loaded.
How can I do this?
Thanks.
 
Philippe Lhoste
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's something extremely hard, or even impossible to do, at least in a cross-browser way. Unless I am proven otherwise... :-)

At one time, I just tried to detect with JavaScript when the user closes the current tab or the whole window (to logout automatically).
There are onUnload and onBeforeUnload events in JavaScript, but only some browsers support it, as the modern versions drop it: it have been too abused by JavaScript ad popups... Opera, for example, doesn't support it at all. And beside this event is triggered on a simple page refresh.

But I digress, that's not what you asked for.
Come to think of it, a possible way to explore is to use onBlur, ie. to check if the page (or the applet, perhaps) lost the focus. Not sure if that's reliable, might happen, eg., if the user just go to the browser's menu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic