In this example you will learn, how to launch Bootstrap modal on page load. 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Open Bootstrap Modal on Page Load</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/bootstrap-theme.min.css"> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script src="js/bootstrap.min.js"></script> <script> $(document).ready(function(){ $("#myModal").modal('show'); }); </script> </head> <body> <div id="myModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Subscribe our Newsletter</h4> </div> <div class="modal-body"> <p>Subscribe to our mailing list to get the latest updates straight in your inbox.</p> <form> <div class="form-group"> <input type="text" class="form-control" placeholder="Name"> </div> <div class="form-group"> <input type="email" class="form-control" placeholder="Email Address"> </div> <button type="submit" class="btn btn-primary">Subscribe</button> </form> </div> </div> </div> </div> </body> </html> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.