You'll need using some client side scripting which does this check during the onbeforeunload event.
var showPrompt=true;
var isModified=false;
var hidePopup=false;
function onBeforeUnload() {
if (showPrompt) {
if (isModified) {
if (hidePopup || confirm("Click ok to save your changes or click cancel to discard your changes.")) {
doSave();
}
}
}
showPrompt = true;
hidePopup = false;
}
- showPrompt can be set to false when your clicking on an anchor tag which won't navigate you away from the page. For example
<a onclick="showPrompt=false" href="javascript:doX()" />
- isModified can be used to track when you need to save something. You could for example do something like
$("input").onchange(function(){isModified=true;});
To track undo's you might want to replace isModified with a function which checks the current state from the last saved state.
- hidePopup lets us force a save without confirming to the user.