How to disable “[removed]” when submit form?

2019-07-16 08:00发布

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 show this alert box . how i disable this when submit form it should not be ask and show alert box ??

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

    <div>
          <input type="submit" name="" class="button" value="Save Your Application Form" onclick="if(document.getElementById('thumb').value=='') { alert('Please select your photograph.'); return false; } return confirm('Read your application form thoroughly before submitting, Once submitted data, it will not changed in any case, press OK to submit or press CANCEL to make corrections.'); return false;" style="text-align:center !important; float:none !important;"/>
    </div>

2条回答
地球回转人心会变
2楼-- · 2019-07-16 08:29
$(document).on("submit", "form", function(event){
        window.onbeforeunload = null;
});

Should do the trick

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-16 08:32

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;
      return true;
    };
    WinPrint.document.write('<span style="font-size:22px">' + prtContent.innerHTML + '<span>');
</script>
查看更多
登录 后发表回答