我想显示一个 jquery ui 对话框,如果用户要重新加载,请关闭浏览器。我试过了 :
$(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');
            }
        }
    });
});
但是页面正在重新加载,但没有显示确认对话框。如果我放一个 return 语句,那么它会显示一条一般警报消息。但我想显示一个对话框。我怎样才能做到这一点 ?