Capture Event, when browser closed

//Here i’m updating the login status of user when user closed the browser.
//Write a method to update the status
 
 

protected void Inactive()

 

{

DAL.Updatestatus(Session["UserName"].ToString(), false);

}

//Event for logout

protected void Button1_Click(object sender, EventArgs e)
 {

Inactive();

}

//Javascript method to capture the browser close event.
//If  user clicks on browser close document readystate is ‘Complete’ else ‘Loading’
 
 

<script type=”text/javascript”>
 function abc()
 {
 
 

 
 
 
 
 

 

var status = document.activeElement;

if(status ==null)

{

document.getElementById(‘<%=Button1.ClientID %>’).click();}

}

</script>

//call the javascript method on page unload.

<body onunload=”abc();” >
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.