K
K
Kanat2019-02-24 10:42:54
css
Kanat, 2019-02-24 10:42:54

How to make modal window open in bootstrap on page load?

I write the modal window like this:

<div class="modal fade in" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

but nothing happens when the page loads. Js included bootstrap.min.js and jquery files.
And what is strange is that in the source code of the browser, it does not exist at all.
When I start it with the button everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2019-02-24
@harasaev

So where is the script call so that the window opens on boot? Accordingly id add to your window

<script type="text/javascript">
    $(window).on('load',function(){
        $('#myModal').modal('show');
    });
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question