Solved

javascript on browser close button

Posted on 2008-11-01
4
589 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

707 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