0

How can I solve this issue?

<div class="modal fade" id="onload-modal">
  <!-- data-backdrop="static" data-keyboard="false" -->
  <div class="modal-dialog modal-dialog-centered modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">
        <p><img src="#" id="modal-banner" alt="Image"></p>
      </div>
      <div class="modal-footer">
        <button class="btn btn-danger" data-dismiss="modal">Skip</button>
        <button class="btn btn-danger" onclick="#">Register Now</button>
      </div>
    </div>
  </div>
</div>

It seems like some other code is clashing with this code. Can you please help?

<script>
  $(document).ready(function() {
    $("#onload-modal").modal('show');
  });
</script>
Behemoth
  • 5,389
  • 4
  • 16
  • 40
  • Does this answer your question? [Launch Bootstrap Modal on page load](https://stackoverflow.com/questions/10233550/launch-bootstrap-modal-on-page-load) – Don't Panic May 30 '21 at 07:35

1 Answers1

0

Instead of showing the modal when the document is ready, try to show the modal when the window is loaded, as below:

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <div class="modal fade" id="onload-modal">
        <!-- data-backdrop="static" data-keyboard="false" -->
        <div class="modal-dialog modal-dialog-centered modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title"></h4>
                </div>
                <div class="modal-body">
                    <p><img src="#" id="modal-banner" alt="Image"></p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-danger" data-dismiss="modal">Skip</button>
                    <button class="btn btn-danger" onclick="#">Register Now</button>
                </div>
            </div>
        </div>
    </div>


    <!-- jQuery first, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    <script>
      $(window).on('load', function()
       {
      $("#onload-modal").modal('show');
       });
    </script> 
  </body>
</html>
kayuapi_my
  • 498
  • 1
  • 6
  • 9