We have a typical web application that is essentially a data entry application with lots of screens some of which have some degree of complexity. We need to provide that st
Additional to Lance's answer, I just spent an afternoon trying to get this snippet running. Firstly, jquery 1.4 seems to have bugs with binding the change event (as of Feb '10). jQuery 1.3 is OK. Secondly, I can't get jquery to bind the onbeforeunload/beforeunload (I suspect IE7, which I'm using). I've tried different selectors, ("body"), (window). I've tried '.bind', '.attr'. Reverting to pure js worked (I also saw a few similar posts on SO about this problem):
$(document).ready(function() {
$(":input").one("change", function() {
window.onbeforeunload = function() { return 'You will lose data changes.'; }
});
$('.noWarn').click(function() { window.onbeforeunload = null; });
});
Note I've also used the ':input' selector rather than enumerating all the input types. Strictly overkill, but I thought it was cool :-)