I'm catching the page close/refresh event by following code:
window.onbeforeunload = function(){
jQuery("#submit_form_button").click();
jQuery("#saving_loader").show();
};
Here, the line jQuery("#submit_form_button").click();
sends a request to controller#update method and saves the form before reload. The only problem is, it works sometimes and sometimes not. Specifically I'm seeing this problem in Chrome.
So I want to delay the refresh process. It should happen after click()
event. I tried setTimeout() but it doesn't work.
Any suggestions?