0

I want to show a jquery ui dialog , if user will reload, close the browser. I tried :

$(window).bind('beforeunload', function () {
    $("#confirm").dialog({ width: 500, modal: true,
        buttons: {
            "Ok": function () {
              // let the page reload
            },
            "Cancel": function () {
                // cancel reloading the page
                $(this).dialog('close');
            }
        }
    });
});

But the page is reloading without showing confirmation dialog. If i put a return statement then it shows a general alert message. But i want to show a dialog. How can i do this ?

Gaurav
  • 8,367
  • 14
  • 55
  • 90
  • You can't, see; http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own – Alex K. Sep 11 '12 at 13:19

1 Answers1

0

In order to protect users from not being able to leave a page, there are severe restrictions on what can be done on a beforeunload event. You may display a native browser dialog asking for confirmation but not a jQuery UI one.

Here's what you can do.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758