I have a page where the user can start a background process. I'd like to stop this process in case the user refreshes the page or closes the tab or browser. Tried connection_abort()
but no luck, the script just goes on running. Any ideas?
I think you are out of luck. http
is a stateless protocol, as soon as your page is served the connection is closed.
Besides some ajax tricks, there is no way to tell that the user refreshes or closes the browser.
If you have a unique identifier for the user, and this can be tied or stored along with the process id, the following logic could work:
The above is a rather involved solution (and possibly temperamental as it relies on JavaScript) so probably should only be considered if really required or if the target audience can be locked down.
As a non js solution you could rely on the polling method and set-up a meta-refresh frame. However this might send users of older versions of Internet Explorer mad for the constant 'clicking'. Not to mention the solution being rather inelegant.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.