2

I have a beforeunload` handler on my page to catch situations where the user hasn't saved before, for instance, closing the tab.

The code looks like this :

$(window).bind("beforeunload", function(evt) { 
    if (TCG.QUE.changeCount > 0){
        evt.preventDefault();
        var errDlgMsg = "You have unsaved answers. Save the answers before leaving this page or the unsaved answers will be lost.";
        bootbox.alert({message: errDlgMsg, title: "Unsaved Answers"});
        return false;
    }
})

When it fires before the bootbox dialog firing another dialog is displayed which looks like this

enter image description here

I don't want to see that dialog because the bootbox dialog is intended to do the same job. How can I suppress that dialog?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
glaucon
  • 8,112
  • 9
  • 41
  • 63
  • 2
    simple...don't call beforeunload ... there is nothing you can do to prevent the native dialog. Many browsers no longer even let you change the message – charlietfl Sep 22 '15 at 01:08
  • possible duplicate of [How to show the "Are you sure you want to navigate away from this page?" when changes committed?](http://stackoverflow.com/questions/1119289/how-to-show-the-are-you-sure-you-want-to-navigate-away-from-this-page-when-ch) – Tieson T. Sep 26 '15 at 07:49
  • @charlietfl : the more I thought about that more I thought your comment was essentially the right approach. Would you mind putting it in as an answer and then I'll mark it correct ? – glaucon Oct 04 '15 at 08:48

0 Answers0