清除Onbeforeunload [英] Clear Onbeforeunload
问题描述
我有一个用 ajax
提交的文本区域,该文本区域使用onbeforeunload来警告用户,如果他们尝试关闭浏览器,则他们尚未提交该文本区域.问题是我需要以某种方式清除 ajax
提交成功后的onbeforeunload,以便onbeforeunload知道用户已成功提交了表单.有没有一种方法可以使用一行代码来清除onbeforeunload,类似于clearTimeout或clearInterval?我将显示我当前拥有的onbeforeunload代码,尽管我认为这并不重要,但我正在寻找其他函数来清除此问题.请没有框架.谢谢.
I have a textarea that is submitted with ajax
that uses onbeforeunload to warn the user that they have not submit the textarea if they try to close the browser. The problem is I need to somehow clear the onbeforeunload within the success of the ajax
submit so that onbeforeunload knows that the user has submitted the form successfully. Is there a way to clear the onbeforeunload with a line of code, similar to a clearTimeout or clearInterval? I'll show the onbeforeunload code I currently have even though I don't think it matters much b/c I'm looking for a different function to clear this. No frameworks please. Thank you.
函数调用
unsavedChangesWarning();
Onbeforeunload函数
Onbeforeunload Function
function unsavedChangesWarning(){
window.onbeforeunload = function(){
return 'If you close this page you will lose your stride update!';
};
}
推荐答案
window.onbeforeunload = null
将清除它.在尝试将用户重定向到任何地方之前,只需添加此内容即可.
window.onbeforeunload = null
will clear it. Just add this before you try to redirect the user anywhere.
这篇关于清除Onbeforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!