Click here to Skip to main content
15,867,860 members
Articles / Web Development / ASP.NET
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
3.28/5 (23 votes)
2 Sep 2009CPOL 64.2K   21   10
Some times we need to detect the Browser Close to perform some operation before quiting from application. Here is a simple way.function CheckBrowser(){ // Check Browser Close [X] , Alt+F4 , File -> Close if(window.event.clientX < 0 && window.event.clientY <0) { wi
Some times we need to detect the Browser Close to perform some operation before quiting from application. Here is a simple way.
function CheckBrowser()
{
     // 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');
    }
}
Call this Method From Body Unload

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog : http://abhijitjana.net
Web Site : http://dailydotnettips.com
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

Comments and Discussions

 
GeneralMy vote of 1 Pin
sacad15-Sep-13 22:37
sacad15-Sep-13 22:37 
GeneralReason for my vote of 1 it works on in IE Pin
MaulikDusara10-Jun-11 22:36
MaulikDusara10-Jun-11 22:36 
GeneralReason for my vote of 2 Works, bu only in IE. Pin
Manfred Rudolf Bihy8-Mar-11 22:01
professionalManfred Rudolf Bihy8-Mar-11 22:01 
GeneralReason for my vote of 1 Only works in IE :( Pin
That's Aragon5-Mar-11 1:11
That's Aragon5-Mar-11 1:11 
GeneralReason for my vote of 1 Very funny dear, works only in IE Pin
Kanchan Roy18-Jul-10 23:07
professionalKanchan Roy18-Jul-10 23:07 
Generalneed helpp..... Pin
Ajay Kale New2-Sep-10 0:23
Ajay Kale New2-Sep-10 0:23 
QuestionDoes it work in all browser? Pin
Sohel_Rana30-Nov-09 22:41
Sohel_Rana30-Nov-09 22:41 
AnswerRe: Does it work in all browser? Pin
Abhijit Jana30-Nov-09 23:08
professionalAbhijit Jana30-Nov-09 23:08 
GeneralRe: Does it work in all browser? Pin
Suresh Pirsquare8-Dec-09 5:56
Suresh Pirsquare8-Dec-09 5:56 
GeneralRe: Does it work in all browser? Pin
Abhishek Sur12-Jan-10 23:04
professionalAbhishek Sur12-Jan-10 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.