Click here to Skip to main content
11,631,170 members (76,406 online)
Click here to Skip to main content

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

, 7 Mar 2011 CPOL 43.7K 11
Rate this:
Please Sign up or sign in to vote.
Code...

Code

<html>
<head><title>Detect Browser Exit</title>
<script type="text/javascript" language="Javascript">
 
function DetectBrowserExit()
{
   alert('Execute task which do you want before exit');
}
 
window.onbeforeunload = function(){ DetectBrowserExit(); }
 
</script>
</head>
<body>
Detect Browser Exit
</body>
</html>

jQuery

I found the code in jQuery. Clickety[^]

Browser Compatibility

I have tested this script in the following Web browsers:
  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Safari

License

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

Share

About the Author

thatraja
Web Developer
India India
Programmer | Dude | ||||||

About him & his blog? check out here. Currently he's updating the site, he'll return soon there with more things*.

In Codeproject, he posted a blogpost & more than couple of Tip/Tricks, hope he'll write more soon.

Favorite techs are MVC, WCF, Mobile, HTML5, CSS3, jQuery, etc.,

His hobbies are watching movies, CP, being alone, etc., But now he's working on something*.

* - SCAMP???

You may also be interested in...

Comments and Discussions

 
GeneralNice one. Pin
Ramalinga Koushik3-Jun-11 22:43
memberRamalinga Koushik3-Jun-11 22:43 

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.150723.1 | Last Updated 7 Mar 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid