Solved

javascript on browser close button

Posted on 2008-11-01
4
587 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:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
window close link 7 36
arrays and radio buttons 10 40
Put javascript to get dropdown value 3 22
What is the correct way to check for empty value in input field 2 20
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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