How to detect browser close when browser [X] is clicked

No.of Views2228
Bookmarked0 times
Downloads 
Votes0
By  Jana   On  15 Feb 2010 23:02:44
Tag : ASP.NET , How to
How to detect browser close when browser [X] is clicked
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

This article will describe how we can detect the browser when user click on the Close [X] button .

When we need this ?

There are some scenarios where this can be apply

  • We have log off button on web site, and on logoff we are removing some database information of that user and clearing the session. But unfortunately user Click on [X] button . So, what will happen . we can apply this code on that situation.
  • We have to give some Message if user Click [X ] button of the browser


Code


{codecitation class="brush: javascript; gutter: true;" width="650px"}

function DeleteLog()
{
// Check Browser Close [X] , Alt+F4 , File -> Close
if(window.event.clientX < 0 && window.event.clientY <0)
{
window.open("Operation.aspx", "Operation",'left=12000,top=1200,width=10,height=1');
}

}

{/codecitation}



Description :

Call this code from the Body Unload of the form. I have opened an window which will open in a differnt location that you can guess from the left and top position of the popup window. Do what ever function you want to perform on the server side of that popup and the close that popup by using Self.Close()

Hope this will help you.

Thank you

Jana

 
Sign Up to vote for this article
 
About Author
 
Jana
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-19 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top