I'm struggling with onbeforeunload, onunload and generating the right messages at the right time. Any idea welcome. This is the situation:
So for example, if there is data to save. With onbeforeunload, a message pops up, -regardless of the state of the user's data- asking if they want to navigate away or not. With onunload, I can choose the message and check whether there is unsaved data before asking the user, saving them the trouble if they have saved, but my user can't choose to stay on the page.
Am I missing something there? It seems I can't get the simple behaviour I want - check application status, give a message, and offer the user to take action before they leave. Or is there a use of either or both events to get this behaviour?
I made a simple example for you, that I think might do what you want. Unfortunately there is no way to change the message in
onbeforeunload, but you can remove the message when the user saves data. http://jsfiddle.net/JL48j/8/
©2020 All rights reserved.