TitusRevised Posted July 5, 2006 Share Posted July 5, 2006 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] Link to comment https://forums.phpfreaks.com/topic/13765-confirm-page-leave-help/ Share on other sites More sharing options...
Cas Posted July 9, 2006 Share Posted July 9, 2006 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... Link to comment https://forums.phpfreaks.com/topic/13765-confirm-page-leave-help/#findComment-55076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.