清除Onbeforeunload

gmu*_*ent 7 javascript ajax

我有一个提交的textarea ajax使用onbeforeunload来警告用户,如果他们试图关闭浏览器,他们没有提交textarea.问题是我需要以某种方式清除ajax提交成功中的onbeforeunload,以便onbeforeunload知道用户已成功提交表单.有没有办法用一行代码清除onbeforeunload,类似于clearTimeout或clearInterval?我将展示我目前拥有的onbeforeunload代码,即使我认为它不重要b/c我正在寻找一个不同的功能来清除它.没有框架请.谢谢.

函数调用

unsavedChangesWarning();
Run Code Online (Sandbox Code Playgroud)

Onbeforeunload功能

function unsavedChangesWarning(){
    window.onbeforeunload = function(){
        return 'If you close this page you will lose your stride update!';
    };
}
Run Code Online (Sandbox Code Playgroud)

Nie*_*sol 15

window.onbeforeunload = null会清除它.只需在尝试将用户重定向到任何位置之前添加此项.