Refresh parent page after closing modal

2019-06-15 22:57发布

问题:

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();
            }
        }