One way I am currently using is to store data in localStorage when the user leaves the page:
$window.onbeforeunload = function(){
saveSomeDataInLocalStorage();
if($scope.message){
return "You haven't sent your message yet. Do you want to leave without sending?";
}
else
return null;
};
If the condition if($scope.message)
is met, a confirmation message is displayed and the data is successfully saved in localStorage through the saveSomeDataInLocalStorage
function. Everything works perfectly...
However, if the else
condition is met, the data is not saved even when utilizing the saveSomeDataInLocalStorage
function.
It seems like the behavior of the onbeforeunload
event is causing this issue... I am having trouble understanding it.
I am looking for a solution to save the data regardless of whether the confirmation message is shown or not.
Is there a possible workaround for this?
Your help is greatly appreciated!