Click here to Skip to main content
Click here to Skip to main content

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

By , 2 Sep 2009
 
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)

About the Author

Abhijit Jana
Software Developer (Senior)
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
Follow on   Twitter

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 1 it works on in IEmemberMaulikDusara10-Jun-11 22:36 
Reason for my vote of 1
it works on in IE
GeneralReason for my vote of 2 Works, bu only in IE.mvpManfred R. Bihy8-Mar-11 22:01 
GeneralReason for my vote of 1 Only works in IE :(memberThat's Aragon5-Mar-11 1:11 
GeneralReason for my vote of 1 Very funny dear, works only in IEmemberKanchan Roy18-Jul-10 23:07 
Generalneed helpp.....memberAjay Kale New2-Sep-10 0:23 
QuestionDoes it work in all browser?memberSohel_Rana30-Nov-09 22:41 
AnswerRe: Does it work in all browser?mvpAbhijit Jana30-Nov-09 23:08 
GeneralRe: Does it work in all browser?memberSuresh Dayma8-Dec-09 5:56 
GeneralRe: Does it work in all browser?mvpAbhishek Sur12-Jan-10 23:04 

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130619.1 | Last Updated 2 Sep 2009
Article Copyright 2009 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid