开发者

Update the database table and kill the session when the browser closes

I need to update the table when the user closes the browser/tab (IE,FF,Chrome,Opera and Safari).

I placed the unlo开发者_如何学Goad event in MasterPage but the unloading event is firing only the first time. Every other unload event is not firing.


The beforeunload event will do what you want, provided the user is still logged in when they close the browser.

But you can never be 100% certain of getting the event.

The user may lose their network connection, or crash their computer, etc, which would have the same effect, but you'd never get notified of it.

And because it's a client-side action, it could be intercepted by a malicious script or hacked by the user.

The bottom line is: Do NOT rely on this functionality. You need to allow your sessions to die naturally even if are you never notified of the browser being closed. The standard way to do this is with a timeout after a period of inactivity.

And if you're going to allow that anyway, is there any need to actively kill sessions on browser close? You may as well just let them all die naturally with a timeout.


jQuery(window).bind('beforeunload',function(){
      //do what ever
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜