Jump to content

Archived

This topic is now archived and is closed to further replies.

TitusRevised

Confirm page leave help

Recommended Posts

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.
[code]<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()">[/code]

Share this post


Link to post
Share on other sites
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...


Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.