When a user tries to leave the page without saving, I use the beforeunload function to display a popup warning them that their changes may not be saved if they proceed. They can then choose to leave or stay on the page. However, I am facing an issue with this functionality not working on IOS devices such as iPhone and iPad.
var isSkipUnsavedChangePopup = false;
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "Are you sure you want to leave?";
if (!$("#btnSave").prop("disabled") && !isSkipUnsavedChangePopup) {
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
}
});