dan*_*317 3 javascript jquery google-chrome
我实现了一些代码来防止用户从未保存的表单中丢失数据,这些数据本来应该显示这一点,但我的代码似乎没有被执行。我的代码:
$(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');
});
Run Code Online (Sandbox Code Playgroud)
与此票证中提取的内容类似:离开页面时显示带有“onbeforeunload”的警告,除非单击“提交”
当然,当编辑字段时,还有其他代码将表单标记为脏。
从几天前开始,我的网络应用程序突然开始在每个操作上显示一个窗口,该窗口将使页面显示“您所做的更改可能尚未保存”。
这忽略了我的脏标志和中断所需的加载类,并且不会显示我的自定义消息。
我的问题的措辞被标记为“主观”,但是我尝试以问题的形式表达它,并匹配我在谷歌中搜索的关键词以找到我要发布的解决方案。
删除函数底部的“return false”以恢复条件。Google Chrome 发布了安全更新。随着更新甚至false触发卸载对话框。
我找到了自己的答案,并认为社区将从我的斗争中受益。
至于消息,不再可能自定义这些消息。此更新引起的另一个问题也在此票证上得到解决:javascript onbeforeunload not shown custom message
| 归档时间: |
|
| 查看次数: |
6717 次 |
| 最近记录: |