以下代码工作正常,但我想要javascript警报,而不是Windows警报。
unsaved = false;
$(":input").change(function () {
unsaved = true;
});
$(document).on("submit", "form", function (event) {
unsaved = false;
$(window).off('unload');
});
function unloadPage() {
if (unsaved) {
return "You have unsaved changes on this page. Do you want to leave page?";
}
}
window.onbeforeunload = unloadPage;