?
Solved

javascript on browser close button

Posted on 2008-11-01
4
Medium Priority
?
590 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 1000 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 1000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

777 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