Pop up with Bootstrap when loading page

Asked

Viewed 14,365 times

4

How can I get a Bootstrap pop up when loading the page?

<button class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Small modal</button>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>
  • 1

    This is how it should work. You’re importing JS from Bootstrap?

1 answer

10


First apply an ID to the modal:

<div id="myModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

There in tags <script></script> place:

$(document).ready(function() {
   $('#myModal').modal('show');
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.