禁用“您所做的更改可能无法保存”弹出窗口 [英] Disable "Changes you made may not be saved" pop-up window
本文介绍了禁用“您所做的更改可能无法保存”弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下前端代码导出 .csv
文档。
I use the following frontend code to export a .csv
document.
HTML
<form id="tool-export" method="post" action="export/">{% csrf_token %}
<a id="export-link" class="btn btn-sm btn-primary" href="#">DOWNLOAD</a>
</form>
JS
$('#export-link').click(function(e) {
e.preventDefault();
var link = $(this);
var form = link.closest('form');
var project_id = proj_id.find(":selected").val();
var input = $('<input>').attr('type', 'hidden').attr('name', 'project_id').val(project_id);
form.append($(input));
var project_type = proj_type.val();
input = $('<input>').attr('type', 'hidden').attr('name', 'project_type').val(project_type);
form.append($(input));
form.submit();
});
导出效果很好,我得到了正确的文件。但是,在点击导出链接后,我收到 您所做的更改可能无法保存 消息。如何禁用此消息?我不想看到它。
Export works well and I get the correct document. But also I receive the Changes you made may not be saved message after clicking on the export link. How to disable this message? I don't want to see it.
推荐答案
@Dekel帮我搞定了。
@Dekel helped me to get it.
消息是 beforeunload 事件。
我可以用 window.onbeforeunload = null;
来禁用它。
The message is the beforeunload event.
And I can disable it with window.onbeforeunload = null;
.
JS
$('#export-link').click(function(e) {
window.onbeforeunload = null;
e.preventDefault();
var link = $(this);
var form = link.closest('form');
var project_id = proj_id.find(":selected").val();
var input = $('<input>').attr('type', 'hidden').attr('name', 'project_id').val(project_id);
form.append($(input));
var project_type = proj_type.val();
input = $('<input>').attr('type', 'hidden').attr('name', 'project_type').val(project_type);
form.append($(input));
form.submit();
});
这篇关于禁用“您所做的更改可能无法保存”弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文