如何在提交表单时禁用“window.onbeforeunload”?

2024-04-22

当我从浏览器关闭此页面时,会打开一个警告框,询问“离开此页面”或“留在此页面”,没关系。但是,当从下面给出的“提交”按钮提交表单时,它会再次询问并显示此警报框。我如何在提交表单时禁用此功能,不应该询问并显示警报框?

<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;
});

应该做的伎俩

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在提交表单时禁用“window.onbeforeunload”? 的相关文章