I need to warn users that they will lose information when they exit the page. This is easy to do using the onbeforeunload event. My problem is that I want to take some action if the user decides to leave.
Here is an example (I use jquery because it is loaded anyway):
$(window).on('beforeunload', function(e){
return "Do you really want to leave?";
});
What I would like to do is something like this (this code does not work, I know, this is just an example to illustrate what I'm trying to do):
$(window).on('beforeunload', function(e){
var bUserAnswer = confirm("Do you really want to leave?");
if(bUserAnswer)
{
}
else
{
}
return bUserAnswer;
});
I have no idea that what I'm trying to do here is even possible ... Walking around did not give me any directions anyway, so I turn to my favorite group of experts!
Any idea how I could do this?
Thank!