显示msgbox后停止页面重定向

时间:2017-01-07 20:21:54

标签: jquery msgbox

我希望页面在显示msgBox时停止重定向,并等待用户按下该框上的按钮。

我可以在页面卸载时显示msgbox,但页面仍会重定向到另一个网页而不等待用户的输入。

<script>
    $(window).bind('beforeunload', function () {
        msgbox();
    });

    function msgbox() {

        $.msgBox({
            title: "Confirmation",
            content: "Do you agree with the information provided?",
            type: "confirm",
            buttons: [{ value: "Yes" }, { value: "No" }],
            success: function (result) {
                if (result == "Yes") {
                    window.location.replace("somepage/controller/func2");
                } else {
                    window.location.replace("somepage/controller/func1");
                }
            }
        });
    }
</script>

1 个答案:

答案 0 :(得分:0)

触发msgbox时可能会设置一些重定向吗?

试试这个:

$(window).bind('beforeunload', function () {
    msgbox();
    return false;
});

添加Return false将阻止进一步处理,并控制进一步执行到msgBox。

相关问题