Skip to content Skip to sidebar Skip to footer

How To Disable "window.onbeforeunload" When Submit Form?

When i close this page from browser a alert box is open to ask 'Leave this page' or 'stay on this' that is ok. But when submit form from Submit button given below it again ask and

Solution 1:

$(document).on("submit", "form", function(event){
        window.onbeforeunload = null;
});

Should do the trick

Solution 2:

You can use onsubmit event and remove onbeforeupload listener in it, so, modified script:

<script>window.onbeforeunload = function(e) {
      return'You application form is not submitted yet.';
    };
    document.getElementById("your_form_id_here").onsubmit = function(e) {
      window.onbeforeunload = null;
      returntrue;
    };
    WinPrint.document.write('<span style="font-size:22px">' + prtContent.innerHTML + '<span>');
</script>

Post a Comment for "How To Disable "window.onbeforeunload" When Submit Form?"