如何禁用"window.onbeforeunload"何时提交表格? [英] How to disable "window.onbeforeunload" when submit form?

查看:134
本文介绍了如何禁用"window.onbeforeunload"何时提交表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从浏览器关闭此页面时,将打开一个警告框,询问是否可以离开此页面"或保持在此状态".但是,当从下面给出的提交"按钮提交表单时,再次询问并显示此警报框.我应该如何禁用它,当提交表单时不应该问它并显示警报框??

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>

推荐答案

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

应该做到这一点

这篇关于如何禁用"window.onbeforeunload"何时提交表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆