PDA

View Full Version : Want to Capture Window Close Event


dhiru
07-23-2003, 04:18 PM
I want to capture Window close event. UnLoad will not help me as this event will be called whenever it is redirected to other page.

I want as soon as user try to close the window i want to display an confirm message if user Click Ok then browser will be closed and if cancel it will not.
Can anybody help me out on this.

Dhiru

beetle
07-23-2003, 04:37 PM
This is nigh-impossible. The events and properties simply aren't there.

The only solution is to open a second window to monitor the status of another, but you'll never get the control to present the user with a confirm dialog (HTAs might let you do this, but they are pretty much for intranets only)

RoyW
07-23-2003, 09:43 PM
The following is IE only and is by no means a perfect solution

<html>
<head>
<title> NO close</title>
<script>

var clicked = false

document.onclick = function()
{
if(event.srcElement.tagName == "A")
clicked=true;
}

</script>

</head>
<body onbeforeunload="if(!clicked) return 'YOUR MESSAGE HERE'">

<a href="http://www.google.com">Google</a><br>
<a href="http://www.google.com">Google</a><br>
<a href="http://www.google.com">Google</a><br>

</body>
</html>


It kindof works, but if the user refreshes the page they get the 'confirm close' message which is not nice. Also you have to put the script in every page.

You might be able to do something with hidden frames/iframes, I dunno.

Abha
10-08-2009, 10:47 AM
Can anybody tell me how can we do this through the iFram. I want to capture window close only. don't want to do anything on refresh.

Philip M
10-08-2009, 11:09 AM
Same answer as seven years ago - not possible.

There is no way to distinguish between window close and refresh.

And the same answer as I gave you in:-

http://www.codingforums.com/showthread.php?t=179031

Not possible.
OK?