在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;
}
});
}