I have the following code
var _this = this;
window.addEventListener("beforeunload", function(e) {
_this.save(form);
});
Is it possible to only unload the page after this save function has completed? It seems to be working 75% of the time, however in cases will just unload before it has a chance to save.
My save function
Navigation.prototype.save = function(form) {
if(!this.check_completed()) {
this.handle_percentage();
this.strip_space(form);
form[0].getElementsByClassName("gform_save_link")[0].click();
}
}