Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload page on closing a Bootstrap 3 modal

My aim is to get the page to reload when a Bootstrap modal is closed. The user can close the modal by clicking on the close button or icon or by clicking away from the modal.

My code so far is pretty standard. Taken from: http://getbootstrap.com/javascript/#modals

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">My title</h4>
      </div>
      <div class="modal-body">
        My content
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </div>
</div>

How can I get the page to reload after a modal is closed?

Update: Wow, fantastic fast response from everybody. Thank you

like image 845
henrywright Avatar asked Feb 05 '14 13:02

henrywright


People also ask

How do I close a Bootstrap modal?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

How do I stop a Bootstrap modal from closing?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How do I load a page in modal?

You can use the Bootstrap . modal('show') method for launching the modal window automatically when page load without clicking anything. A common example of this technique is loading the modal when user landed on the home page and requesting them to subscribe the website newsletter.


Video Answer


3 Answers

You can bind the event to reload page on click of close:

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

Demo

like image 87
Milind Anantwar Avatar answered Oct 21 '22 02:10

Milind Anantwar


try this with your button:

onclick="javascript:window.location.reload()"

full button:

<button type="button" onclick="javascript:window.location.reload()" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

example: http://jsfiddle.net/Valtos/52VtD/2288/embedded/result/

like image 23
Manuel Richarz Avatar answered Oct 21 '22 02:10

Manuel Richarz


$('#myModal').on('hidden', function () {
  document.location.reload();
})

Demo

like image 7
124 Avatar answered Oct 21 '22 03:10

124