我有一个按钮:
<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();
这将在使用
onbeforeunload
将浏览器重定向到新页面之前删除location.href
事件。关于javascript - 使用window.location.href防止“确认导航”警报,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40897571/