I need to warn users about unsaved changes before they leave a page (a pretty common problem).
window.onbeforeunload=handler
This works bu
What worked for me, using jQuery and tested in IE8, Chrome and Firefox, is:
$(window).bind("beforeunload",function(event) {
if(hasChanged) return "You have unsaved changes";
});
It is important not to return anything if no prompt is required as there are differences between IE and other browser behaviours here.