Refresh parent page after closing modal

♀尐吖头ヾ 提交于 2019-12-08 15:29:28

问题


When a user opens this modal, they can see their shopping cart information and delete items(other jquery) on the modal.

But how could I refresh the parent page after a user closes up the modal?

I read several posts but did not find any useful information for my situation. I know I need to use something like window.location.reload(true); Where should I put that in the code?

$(function(){

    $('#main').off('click.login').on('click.login',function(){

        $('body').loadmodal({

            id:'cart',
            title:'Shopping Cart',
            url:'/cartDisplay/',
            width: '550px',
        }); 


    });
});

Update

    $(function(){
    $('#main').off('click.login').on('click.login',function(){

        $('body').loadmodal({

            id:'cart',
            title:'Shopping Cart',
            url:'/polls/cartDisplay/',
            width: '550px',

        }); 


    });

    $('#cart').on('hidden', function () {
        window.location.reload(true);
    })

});

回答1:


Try this.

  $("#cart").on('hide', function () {
        window.location.reload();
    });



回答2:


I assume that you are using Twitter Bootstrap

Bootstrap 3

$('#cart').on('hidden.bs.modal', function () {
    window.location.reload(true);
})

Bootstrap 2.3.2

$('#cart').on('hidden', function () {
   window.location.reload(true);
})



回答3:


As far as I can tell, jquery.loadmodal.js has bootstrap.js as a dependency, so its modals are still subject to bootstrap's methods.

In that case, you can simply bind to hidden.bs.modal

...
$('#yourModal').on('hidden.bs.modal', function () {
    location.reload();
});
...



回答4:


Where you open the nyroModal window, just add this callback function:

 callbacks: {
       afterClose: function() {
              window.location.reload();
            }
        }


来源:https://stackoverflow.com/questions/22952713/refresh-parent-page-after-closing-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!