0

I have a function corresponding to the unload event in my form:

window.onbeforeunload = function() {
        return "Your work will be lost.";
};

This function works every time the page is refreshed. However I want that the function should not be executed when the user submits the form. How can I do this using Javascript or JQuery ?

  • A form submit refreshes the page, so cancel that default functionality. – Spencer Wieczorek Dec 30 '17 at 15:44
  • It would be useful to be able to take a look at your form to see how it works. However, it sounds like you could probably add an onclick action listener to the form button and perform the actions you wish there, rather than every time the page loads. – Daniel G Dec 30 '17 at 15:45
  • you might want to look into using separate listeners to do your current `.onbeforeunload` function instead of hooking everything to a generic one. – Kyle Yeo Dec 30 '17 at 15:53
  • I would add a event to capture the submit action, somethig like https://stackoverflow.com/questions/7410063/how-can-i-listen-to-the-form-submit-event-in-javascript, and reafect the on onbeforeunload to return null. – Stephane Duteriez Dec 30 '17 at 15:58

0 Answers0