MyBB Community Forums

Full Version: Are you sure you want to leave this page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How about displaying a message "are you sure you want to leave this page?" when the user has typed something into the reply box but suddenly decides to leave the page.

Now that MyBB is using jQuery it should be easy to implement this feature. Does anyone know how? Smile
Might be something like :
jQuery(function($) {
   $(window).bind('beforeunload', function(){
     if ($('#message').val().length>0) {
      return 'Do you really want to quit page ?';
   }
   });
});
Problem is that some browsers (such as Safari) already have this built into them, so you would also have to detect if that is the case rather than having multiple annoying pop up boxes.
(2015-05-05, 10:26 AM)Euan T Wrote: [ -> ]Problem is that some browsers (such as Safari) already have this built into them, so you would also have to detect if that is the case rather than having multiple annoying pop up boxes.

This sounds to me as if Safari implemented this feature poorly. Wouldn't one of these popup boxes prevent the other one from being triggered in the first place?
I don't believe so, no. I haven't tested it though.