javascript - 使用 window.location.href 防止 'Confirm Navigation' 警报

标签 javascript jquery navigation

我有一个按钮:

<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; 我仍然收到弹出警告:

enter image description here

如何防止这种情况发生?

最佳答案

解决办法如下:

$(window).unbind();

这将在使用 location.href 将浏览器重定向到新页面之前删除 onbeforeunload 事件。

关于javascript - 使用 window.location.href 防止 'Confirm Navigation' 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897571/

相关文章:

javascript - jquery-ui Accordion : adding rows without destroying and recreating?

jquery - 如何使用 Jquery 检查两个元素是否切换?

javascript - 如何为进度条制作三 Angular 形设计

html - 创建下拉菜单,子菜单出现在鼠标悬停时

ajax - 从内部页面进入站点时,jQuery Mobile 哈希导航在多页模板中不起作用

javascript - 从服务器序列故障转移加载 .js?

javascript - onFormSubmit 触发器在谷歌脚本中不起作用

javascript - 为什么列表项在 body 滚动时没有改变?

ios - 无法单击列表中的 NavigationLink (SwiftUI)

javascript - vue.js CLI 应用程序中的 <b-list-group-item> 未呈现 bootstrap-vue