Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2325 times.
Similar Threads
applet
servlet and thread clarification
Need to handle the user opening a different application or opening a new tab
Insider's Guide to Mixing Swing and JavaFX
some problems regd threads as in velmurugan's notes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:54:04.