mechalier
Here is on example with the onbeforeunload :
1. main script (script.php) in which the "leaving" is watched (NB : this script had been opened through a existing window (with a "_blank" target in the form) :
....
<script type='text/javascript'>
window.onbeforeunload = function() {
//in case of a close action with the white cross in the red square in the title bar
if (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 15)) {
//action to fire when leaving...
window.opener.location.href='target.php5 pctid_toclose=< php echo $_SESSION['pctid']; >';
// alert('user is leaving...');
}
}
</script>
....
2. targeted script (target.php) in which an action is done if needed:
....
if($_GET['pctid_toclose'] === $_SESSION['pctid']) {
//actions to do (updating DB for example)
.....
unset($_SESSION['pctid']);
echo "<script type='text/javascript'>document.location.href='index.php5';</script>\n";
exit();
}
.....
But Renee's method is probably more reliable since my method is not working if the user click the top left icon and/or press Alt+F4... :-(
Happy new year to all of you
--Matt