problem for window closing code

Posted by Abhi_patil under ASP.NET on 4/17/2009 | Views : 1438 | 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");

xmlhttp.open("GET"," AbandonSession.aspx",false); //here i made session abondon.

xmlhttp.send();
return;
}
}

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




Responses

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

Up
0
Down
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'
window.open("logout.html?close=true","logoutWindow",settings);
} else {//:ehh:

}
}


window.onunload = initUnload;
</script>


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
[Administrator]

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

Login to post response