【发布时间】:2012-12-30 19:21:36
【问题描述】:
我有一个使用 ajax 提交的 textarea,它使用 onbeforeunload 警告用户如果他们尝试关闭浏览器,他们还没有提交 textarea。问题是我需要在ajax 提交成功的情况下以某种方式清除 onbeforeunload,以便 onbeforeunload 知道用户已成功提交表单。有没有办法用一行代码清除 onbeforeunload,类似于 clearTimeout 或 clearInterval?我将展示我目前拥有的 onbeforeunload 代码,尽管我认为这并不重要,因为我正在寻找一个不同的函数来清除它。请不要框架。谢谢。
函数调用
unsavedChangesWarning();
Onbeforeunload 函数
function unsavedChangesWarning(){
window.onbeforeunload = function(){
return 'If you close this page you will lose your stride update!';
};
}
【问题讨论】:
标签: javascript ajax