I want to check if any textareas in a page were changed, and if so, if the user navigates away without submitting, to stop the navigation and promp a modal window (instead of the one from onbeforeunload) to check if the user wants to realy leave the page or stay and submit the data.
So far I've made this:
var needToConfirm = false;
$("input,textarea").on("input", function () {
needToConfirm = true;
});
$("select").change(function () {
needToConfirm = true;
});
function closeEditorWarning() {
if (needToConfirm) {
var t = News;
t.config.modalTitle.html("If you exit this page, your unsaved changes will be lost"), t.config.modalMsg.text("Are you sure you don't want to submit the changes?"), t.config.modalWindow.show(), t.config.modalAcceptBtn.on(click, null)
return "null";
}
}
window.onbeforeunload = closeEditorWarning();
With this I get the modal popup showing but then the page gets unloaded to the one the user selected right away ignoring the modal window. So how do I prevent the page from being unloaded and make it wait for the user to confirm he wants to leave without submitting the changes?