Solved

javascript on browser close button

Posted on 2008-11-01
4
583 Views
Last Modified: 2011-05-15
Hi,

I got one javascript which is solving my issue but I need your help to make it completly working. In the enclosed javascript when I click browser close button then popup is appearing fine. It provides me two option "ok" and "cancel". When I click "ok" button then it is not showing me alert.
 alert("Window is closed");
Can you please help. I am enclosing code

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>  <TITLE> Window Close Test </TITLE>  <META NAME="Generator" CONTENT="EditPlus">  <META NAME="Author" CONTENT="">  <META NAME="Keywords" CONTENT="">  <META NAME="Description" CONTENT="">  
  <script type="text/javascript">
 var myclose = false;
 function ConfirmClose(){
 if (event.clientY < 0)
 {
 event.returnValue = 'Any message you want';      
 setTimeout('myclose=false',100);
 myclose=true;            
 }
 }
 function HandleOnClose()      {
 if (myclose==true)      {
 alert("Window is closed");
 //you can write your specific code here to call action            
 }
 }
 </script>
 </HEAD>
 <BODY>
 <body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">
 <input type="submit" name="add" id="add" value=" ADD " tabindex="19" />&nbsp;&nbsp; &nbsp;
 <input type="submit" name="edit" id="edit" value=" EDIT " tabindex="20" />&nbsp;&nbsp; &nbsp;
 <input type="submit" name="delete" id="delete" value="DELETE" tabindex="21" />&nbsp;&nbsp;&nbsp;&nbsp;  
 </BODY></HTML>  
0
Comment
Question by:sanrich
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
wilq32 earned 250 total points
ID: 22859676
Well, first of all I wouldnt count too much on onunload event, but if you want this... im not sure that this line will even be true...:

 if (event.clientY < 0)


remove it and bracers and check is that what you want
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
ID: 22861474
That test is IE specific way to test the close button was clicked and is needed - however you are completely correct in saying one should not rely on catching the close event
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35763005
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now