Click here to Skip to main content
12,702,969 members (31,237 online)
Click here to Skip to main content
Add your own
alternative version

Stats

70.2K views
12 bookmarked
Posted

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

, 7 Mar 2011 CPOL
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
Retired from Q/A section & Technical forums since 2014

More coming soon....

You may also be interested in...

Pro
Pro

Comments and Discussions

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

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 7 Mar 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid