javascript - 使用 Facebook 等模式确认离开页面的导航?

标签 javascript jquery html twitter-bootstrap navigation

我正在尝试使用 bootbox.js 给出一个模式确认框。这是 fiddle ..

我的代码看起来像这样,但问题是 native javascript 确认掩盖了我使用 bootbox 的自定义确认框。插件:

$(window).bind('beforeunload', function(){
   var conf = "All unsaved changes will be lost, are you sure you want to leave the page?";         

   return bootbox.confirm(conf, function(result) 
            {
                return result;
            });
        });

任何人都可以告诉我出了什么问题或帮助我了解出了什么问题..?

提前致谢

最佳答案

在本例中使用 jQuery。为了方便起见,我在 anchor 标记中添加了一个“确认”类。您可以使用

阻止默认行为
e.preventDefault

然后在 Bootstrap 箱回调中执行其他过程,并在用户提供响应后进行导航。

$('a.confirmation').click(function(e){
    e.preventDefault();
    var $link = $(this);

    bootbox.confirm({
        message: "Are you sure you want to continue?",
        callback: function (result) {
            if(result){ window.location.href = $link.attr('href'); }
        }
    });
});

关于javascript - 使用 Facebook 等模式确认离开页面的导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21580215/

相关文章:

javascript - 如何在网页上重新加载 Javascript 文件?

javascript - Internet Explorer 11 中的 Web Worker 分析

javascript - 在提交时将值传递给变量后尝试更改页面内容而不重新加载

html - 如何使 HTTP/CSS 复选框 slider 正常工作?

html - CSS 中的 3 行布局

javascript - 插槽内子组件中的触发方法,$refs 不起作用

javascript - 在击键事件期间难以访问类方法

javascript - 我如何使用 jquery mobile 在两个单独的 html 文件之间传递对象

javascript - 如何使一个选择框的值驱动第二个选择框的选项

javascript - jQuery 航点未在正确位置触发