Binding onunload event to prevent loss of entered reply text
It is already implemented eg. in Wordpress CMS - when user enter a text into a field, a flag is set that makes the browser ask user for confirmation before leaving the page.
Example code:
var inputChanged = false;
function navigateAway() {
if(inputChanged) {
return 'If you leave this page, the text you have entered will be lost.';
}
}
$(window).bind('beforeunload', navigateAway);
$(document).delegate(':input', 'change', function(e) { inputChanged = true; });
$(document).delegate('a', 'click', function() { inputChanged = false; });
$(document).delegate('form', 'submit', function() { inputChanged = false; });
