开发者

Is there any technology to kill the user login session if user close the browser?

开发者 https://www.devze.com 2022-12-29 20:37 出处:网络
This should work if multiple windows are open. My applica开发者_JS百科tion is in J2EE. I already tried some javascript like on window.unloadn but this kind of solution is not solid.If you mean on th

This should work if multiple windows are open.

My applica开发者_JS百科tion is in J2EE.

I already tried some javascript like on window.unloadn but this kind of solution is not solid.


If you mean on the server side, the best way is to implement a heartbeat. If none of the windows from this webapp are open, nothing sends a heartbeat, and a server after some time will know the app is disconnected.

If you mean on the client side, there's no 100% reliable way, since the browser might die from external causes (kill/crash/reboot), but a timed-out cookie that is updated regularly in a heartbeat-like fashion might work


HTTP is a stateless, meaning you can't tell when a browser is closed.

Your attempt to use window.onunload does not always work because the browser could exit before executing your event handler.

The technology used to find out if a user has closed their browser (or a best guess) is to use timeouts. Sessions will automatically timeout (this is configurable) - in asp.net the default is 20 minutes. If there is no activity, the timeout kicks in.

0

精彩评论

暂无评论...
验证码 换一张
取 消