我有一个按钮:
<button type="button" class="btn btn-primary mt15 send-emails" name="SendEmails" value="true">Send Emails</button>
还有一个方法:
$('.send-emails').click(function (e) {
// build data and other stuff
$.post('/leads/sendemails', data, function (data, status, xhr) {
alert('Emails have successfully been queued for sending.');
window.onbeforeunload = null;
window.location.href = '/Leads/Lead/' + @Model.LeadID;
}, 'json');
});
即使使用 window.onbeforeunload = null;
我仍然收到弹出警告:
如何防止这种情况发生?
最佳答案
解决办法如下:
$(window).unbind();
这将在使用 location.href
将浏览器重定向到新页面之前删除 onbeforeunload
事件。
关于javascript - 使用 window.location.href 防止 'Confirm Navigation' 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897571/