Click here to Skip to main content
11,647,644 members (66,083 online)
Click here to Skip to main content

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

, 2 Sep 2009 CPOL 35.2K 21
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Abhijit Jana
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

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 Only works in IE :( Pin
That's Aragon5-Mar-11 1:11
memberThat's Aragon5-Mar-11 1:11 

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

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

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