I need to prompt the user before leaving the edit page so that he doesn't lose unsaved changes. I've written the following code, but it is buggy. Once the user is on edit page and he declines the refresh operation after pressing F5, the normal refresh never triggers.
$(document.body).on("keydown", this, function (event) {
if (event.keyCode == 116 && isEditPage()) {
if (!confirm('you will lose all the pending changes. are you sure you want to leave this page?')) {
return false;
}
}
return true;
});