I want to trigger logout when I close any tab of my application. I tried
$(window).on('unload', logout);
and $(window).on('onbeforeunload', logout);
That works fine but events also triggered when I reload page. How can I prevent this on reload? Before asking I found some options like event.currentTarget.performance.navigation.type
but no posibility to separate reload and close in this way. Is there any opputurnity to trigger logout only on tab closed?
Asked
Active
Viewed 2,320 times
0

MolecularMan
- 227
- 2
- 16
-
What "upload"? I doubt there's any reliable way to do this. The browser is under no obligation to notify the server that the user is closing anything. – David Jul 25 '17 at 17:52
-
f5 or browser upload button – MolecularMan Jul 25 '17 at 17:53
-
*Re*load, then? – David Jul 25 '17 at 17:53
-
yes, on reload. – MolecularMan Jul 25 '17 at 17:55
-
https://stackoverflow.com/a/66314375/5729064 – Ihor Khomiak Feb 22 '21 at 11:32
1 Answers
0
As per here Is there a way in javascript to detect if the unload event is caused via a refresh, the back button, or closing the browser? there is no way to detect the difference. Even if you could there would be other circumstances where it wouldn't work.

CumminUp07
- 1,936
- 1
- 8
- 21