Jump to content


Photo

Confirm page leave help


  • Please log in to reply
1 reply to this topic

#1 TitusRevised

TitusRevised
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 05:54 PM

The following code is supposed to give a confirmation popup when the user tries to leave the page the script is on. If he/she selects yes then it goes to the page they wanted to go if not i reloads the page.
My question is how do I make it so if they select yes it first directs to a php script which deletes information in the database and then directs them to the page. And if you can somehow get around it reloading if you select no and just close the popup box. Help is much appreciated.
<script language="Javascript">
<!--

var your_message = "Are you sure you want to leave this page?";
var times = 0;

function onul() {
if (times == 0) {
  var leave = confirm(your_message);
  if (!leave) location = self.location;
  times++;
}
}

//-->
</script>
<body onunload="onul()">


#2 Cas

Cas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 09 July 2006 - 11:19 AM

function onul() {
if (times == 0) {
  var leave = confirm(your_message);
  if (!leave) {
    location = self.location;
    times++;
  }
  else location = url('afile.php?refer=filename.html');
}
}

in afile.php do your database stuff then redirect to $_REQUEST['refer'], ie <?php header('Location:'.$_REQUEST['refer']);?>

Something like that, not sure if my code is exact but play around with it.
Not sure how to cancel the onunload event, its possible that if the function just returns false this might do it, but not sure, you'll have to try it...







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users