为什么window.onbeforeunload中的甜蜜警报只是跳过返回值

时间:2017-05-30 14:20:28

标签: javascript sweetalert

在window.onbeforeunload上运行甜蜜警报时,它会忽略返回值并直接离开页面,甚至无需选择选项。我错过了什么。

window.onbeforeunload = ConfirmExit;

    function ConfirmExit() {
        swal({
            title: "Are you sure?",
            text: "If you leave this page without submitting you will lose your progress.",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#5cb85c",
            confirmButtonText: "✔ Continue",
            cancelButtonText: "✖ Cancel",
            closeOnConfirm: true,
            closeOnCancel: true,
            animation: false
        },
            function (isConfirm) {
                if (isConfirm) {
                    return true;
                } else {
                    return false;
                }
            });
    }

0 个答案:

没有答案