为什么chrome显示弹出警告:;您所做的更改可能尚未保存"在每个页面出口

Why does chrome display the pop-up warning: "Changes you made may not have been saved." on every page exit?

本文关键字:quot 保存 出口 警告 显示 chrome 为什么      更新时间:2023-09-26

设置

我实现了一些代码来防止用户从未保存的表单中丢失数据,该表单本应显示这一点,但我的代码似乎没有被执行。我的代码:

$(window).on('beforeunload', function (e)
{
  if ($('.loading').length)
  {
    var confirmationMessage = 'Data is still being saved and/or loaded in the background. Leaving the page may cause your data to not be saved correctly.';
    (e || window.event).returnValue = confirmationMessage; //Gecko + IE
    return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
  }
  if ($('form.detect-dirty.dirty').length)
  {
    var confirmationMessage = 'You have edited but not saved a form on this page.';
    (e || window.event).returnValue = confirmationMessage; //Gecko + IE
    return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
  }
  return false;
});
$(document).on('submit', 'form', function()
{
  $(window).off('beforeunload');
});

类似于从该票证中提取的内容:显示带有';onbeforeunload';离开页面时,除非';提交';被点击

当然,在编辑字段时,还有其他代码会将表单标记为脏。

问题

从几天前开始,我的网络应用程序突然开始显示每个操作的窗口,这些操作会在页面上显示"您所做的更改可能尚未保存">

这忽略了我的脏标志和中断所需的加载类,并且不会显示我的自定义消息。

旁注

我的问题的措辞被标记为"主观",但我试图用问题的形式表达它,并与我在谷歌上搜索的关键词相匹配,以找到我即将发布的解决方案。

删除函数底部的"return false"以恢复条件。谷歌浏览器发布了一项安全更新。更新后,即使false也会触发卸载对话框。

我找到了自己的答案,并认为社区将从我的斗争中受益。

至于消息,则无法再自定义这些消息。此更新引起的另一个问题也在该票证上得到了解决:javascript onbeforeunload未显示自定义消息