How to launch Bootstrap modal on page load?

How to launch Bootstrap modal on page load?

Asked on November 1, 2018 in Bootstrap.
Add Comment

  • 1 Answer(s)

         The Bootstrap .modal(‘show’) method is used for launching the modal window automatically when page load without clicking anything.
    The example of this technique is loading the modal when user landed on the home page and requesting them to subscribe the website newsletter.
    For example:

    <!DOCTYPE html>
    <html lang="en">
    <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=""></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    <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">&times;</button>
                    <h4 class="modal-title">Subscribe our Newsletter</h4>
                <div class="modal-body">
                    <p>Subscribe to our mailing list to get the latest updates straight in your inbox.</p>
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Name">
                        <div class="form-group">
                           <input type="email" class="form-control" placeholder="Email Address">
                        <button type="submit" class="btn btn-primary">Subscribe</button>
    Answered on November 1, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.