javascript - How to check if a function was fired jquery -


i have warning message in project warn end user if closing window before saving form filling out. works fine firing when saved form , try exit out. want warning message pop if users try exit out before saving form. how go ?

below code pops warning message.

jquery(window).bind('beforeunload', function (e) {      var message = "you have attempted leave page. information lost. please submit before exiting page. sure want exit page?";     e.returnvalue = message;     return message; 

});

and save function

save: function (e) {         e.preventdefault();          var = this;          that.height = that.heightfeet * 12 + that.heightinches;         that.urinationfrequencyminutes = that.urinationfrequencyhours * 60 + that.urinationfrequencymins;          var modeldata = kendo.stringify(that);          $.ajax({             type: "post",             url: constants.serviceurl + "form/create/",             data: modeldata,             datatype: "json",             contenttype: "application/json; charset=utf8",             beforesend: function (xhr) {                 $("#loadingbackground").show();                 $("#loadercontainer").show();             }         })         .success(function (e) {             var test = e;             that.set("savecompleted", true);             that.set("savesucceeded", true);         })         .fail(function (e) {             var test = e;             that.set("savecompleted", true);             that.set("savesucceeded", false);         })         .done(function (e) {             var test = e;             $("#loadingbackground").hide();             $("#loadercontainer").hide();         });      }, 

help appreciated! :)

set global variable is_saved true on save success , revert false change in form.

that way can check if information have been saved already.


Comments