I am coding a form and I need a function like stackoverflow have: \"You have started writing or editing a post.\".
I\'ve looked through the code of stackoverflow to
You can do this using window.onbeforeunload like this:
window.onbeforeunload = function() {
return 'Are you sure you want to navigate away from this page?';
};
So in your code, you would put that inside the success
callback of your $.ajax
call.
To unset the confirmation, you can do this:
window.onbeforeunload = null;
Also, see this answer: How can I override the OnBeforeUnload dialog and replace it with my own?