我想在mozilla或IE 8.0或Chrome中关闭选项卡时注销

HI,

Is is possible to kill the session(Logout) if I close my tab. Please let me know if you guys have implemented this.

Thanks, Manish

Use the Javascript onUnload event to call/ping your PHP logout page:

$(window).unload(function() {
  // Send an Ajax request to logout.php
});

However, Carlos Campderrós is right: you probably won't know if the user has multiple tabs open, so you risk logging them out even though all they did was close one of their tabs.

From the jQuery docs (.unload() is a wrapper around the relevant browser functionality):

http://api.jquery.com/unload/

The exact handling of the unload event has varied from version to version of browsers. For example, some versions of Firefox trigger the event when a link is followed, but not when the window is closed. In practical usage, behavior should be tested on all supported browsers, and contrasted with the proprietary beforeunload event.

In other words, you need to additionally proceed the other way around for it to be reliable: give your sessions a very short timeout, and repeatedly ping your server from within each session to keep them alive.

Create a session, but don't store it with a cookie. After they close that tab, or window they will loose that session.