当用户点击Web浏览器窗口中的关闭按钮时,jquery确认框

时间:2014-11-07 10:40:12

标签: javascript c# asp.net-mvc

是否可以实现与Javascript window.confirm()相同的功能当用户点击Web浏览器的关闭按钮或离开页面或重新加载页面时,带有jquery模式对话框的框。

//////javascript code//////


sessionStorage["isTrue"] = false;
$(".PassReqNotes,.datePassed1").change(function () {
    sessionStorage["isTrue"]= true;
});
$(window).bind('beforeunload', function (event) {
    event.preventDefault();
    var sessionValue = sessionStorage["isTrue"].toLocaleString();
    if (sessionValue == "true") {
        isTrue = false;
        sessionStorage["isTrue"] = null;
        //return 'If you leave page, You may lose some changes';
       return window.confirm = dialog();
    }
});



function dialog(event) {
    $("#dialog-confirmPassReq").removeClass('hide').dialog({
        resizable: false,
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i> Delete Photo?</h4></div>",
        title_html: true,
        buttons: [
            {
                html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; ok",
                "class": "btn btn-danger btn-xs btnDeleteActivityPhoto",
                click: function () {
                    $(this).dialog("close");
                    return true;
                }
            },
            {
                html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; Cancel",
                "class": "btn btn-xs",
                "id": "btnClosePassReq",
                click: function () {
                    $(this).dialog("close");
                    return false;
                }
            }
        ]
    });
}

1 个答案:

答案 0 :(得分:0)

window.onbeforeunload = function() {
    //your code
};