When running a sweet alert on window.onbeforeunload it ignores the return values and just leaves the page straight away without you even getting to choose an option. What am I missing.
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;
}
});
}