1 2 3 4 5 6 7 8 9 10 11 12 13 | var _FormModified_ = false ; $(window).bind( "beforeunload" , function (e) { if (_FormModified_) { var msg = "\r\nInformation has changed.\r\nAre you sure you want to leave without saving?\r\n" ; (e || window.event).returnValue = msg; return msg; } }); var FlagModify = function (e) { if (!(/^(?:9|1[6-9]|2[07]|3[3-9]|4[04-5]|9[13]|11[2-9]|12[0-3]|14[45])$/.test((e||window.event).keyCode))) {_FormModified_ = true ;} }; |
1 2 3 4 5 6 7 8 | $(document).ready( function (){ $( "div.inputForm input" ).keyup( function (e){ FlagModify(e); }); $( "div.inputForm select" ).change( function (e){ FlagModify(e); }); }); |
If AJAX or UpdatePanels are used to save the information, a client onclick event must be added which sets _FormModified_ to be false.