02-28-2022, 09:26 PM
There is no reliable way to detect a tab or page being closed that I am aware of other than a timeout on the server side. And in that case, there is no way to kill the cookie any more. You can simply set your cookies to have rather short timeouts and just keep renewing them as the user uses your application. That way when they close, the cookie will disappear within an hour or even minutes depending on the lifetime you assign to the cookie.

