最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to reload page after bootstrap modal closed - Stack Overflow

programmeradmin2浏览0评论
$("#customerAdded").modal("show").on("shown.bs.modal", function () {
                window.setTimeout(function () {
                    $("#customerAdded").modal("hide");
                }, 5000);
                location.reload();                  
            });

Ok, it works. But with location.reload(), despite I change the time, the page is reloaded immediately. I would, after modal closed, that the page was reloaded according the time specified.

$("#customerAdded").modal("show").on("shown.bs.modal", function () {
                window.setTimeout(function () {
                    $("#customerAdded").modal("hide");
                }, 5000);
                location.reload();                  
            });

Ok, it works. But with location.reload(), despite I change the time, the page is reloaded immediately. I would, after modal closed, that the page was reloaded according the time specified.

Share Improve this question edited Jun 17, 2015 at 9:36 Dave asked Jun 17, 2015 at 9:11 DaveDave 1,5125 gold badges31 silver badges49 bronze badges 1
  • window.setTimeout is executing asynchronically. You should put location.reload() in the window.setTimeout method after $("#customerAdded").modal("hide"); – Martin Kostovski Commented Jun 17, 2015 at 9:20
Add a ment  | 

3 Answers 3

Reset to default 3

You could just fire the location.reload() when you hide your modal:

$("#customerAdded")
.modal("show")
.on("shown.bs.modal", function () {
    window.setTimeout(function () {
        $("#customerAdded").modal("hide");
        location.reload(); 
    }, 5000);                 
});
$("#customerAdded").modal("hide").on("hidden.bs.modal", function () {        
        location.reload();                   
});

Here is the code

$('#customerAdded').on('hidden', function () {
    location.reload();
})
发布评论

评论列表(0)

  1. 暂无评论