problem for window closing code

Posted by Abhi_patil under ASP.NET on 4/17/2009 | Views : 1519 | Status : [Member] | Replies : 1
i have wriiten code for event when user closes browser directly.

my code is following in javascript for onbeforeunload event
function handleWindowClose()

if((window.event.clientX<0) || (window.event.clientY<0))

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");"GET"," AbandonSession.aspx",false); //here i made session abondon.


but problem is when i refreshes then also application closes...


Posted by: Vuyiswamb on: 4/20/2009 [Member] [MVP] [Administrator] NotApplicable

Good Morning

A common question on the forums is, if the user closes the browser window, how can they be logged out immediately?

Here's how. Have the following javascript in your window

<script language="JavaScript">

function initUnload()
var top=self.screenTop;
if (top>9000) {
var settings = 'width=1,height=1,left=1,top=1,toolbar=0,scrollbars=0,status=0'"logout.html?close=true","logoutWindow",settings);
} else {//:ehh:


window.onunload = initUnload;

The part in red, logout.html, can be replaced with any server-side scripted page in ASP/PHP/ASP.NET/WhateverFloatsYourBoat. That page should abandon/clear your sessions.

Thank you for Posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response