In my application i am allowing only 3 admin users at a time to log in to the application.
In case where one of the admin user directly closes the window or tab without signing out i need to invalidate the session or
need to decrement the number of admin users who has logged in.

I tried with following scenarios:

1. jQuery(window).bind("beforeunload", function(){
		//alert("You are about to leave the window");
		firstEntry = false;
		if(confirm("You are closing the window. do you want to continue. Click 'Ok' to close or click 'Cancel' to stay back")){
	2. onunload attribute in body tag and called the function loadSrc('logout').

Both of the above solutions failed to work when there are multiple tabs opened in the browser. But either of the above solution is working properly when the user closes the tab and not window.

5 Years
Discussion Span
Last Post by vinay.bharadhwa

The events you are looking for may be onunload & onbeforeunload (non-standard) events. However, these events are tricky and may not be able to achieve what you want. The reason is that these events would be fired when you leave the site via links or click on the "back" button.

The normal way to deal with session expiration is the timeout set at the server side. It is also a good way to teach users to "log out" instead of "close" the browser.


Thanks for your suggestion. Also i tried with window.onbeforeunload = function(){} which worked for me in single window but not in different windows.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.