user5651777
user5651777

Reputation:

Bootstrap modal at first page load

On page loading i am showing user some bootstrap modal window to show him some information. I would like to show this bootstrap modal only on first time, then every one next should not. How to achieve that? Is there something like function disable after first time? This is my simple code:

$(window).load(function () {
            $('#dddd').modal('show')
    });

Upvotes: 1

Views: 2808

Answers (2)

Cristiano Mozena
Cristiano Mozena

Reputation: 21

add this to your js file:

if(window.sessionStorage.fist_load_modal1 === undefined){
    $('.first_load_modal').modal('show')
    window.sessionStorage.fist_load_modal1 = true
}

Now you can use the class 'first_load_modal' to show your modal on fist load.

<div class="modal fade first_load_modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
         CONTENT HERE
        </div>
    </div>
</div>

Obs: Tested in bootstrap 4

Upvotes: 0

0xburned
0xburned

Reputation: 2655

This is a possible duplicate of this

Nevertheless, you can use cookies to achieve this. For your reference the following example is done using jquery cookie

<script src="/path/to/jquery.cookie.js"></script>
<script>
    $(document).ready(function() {
        if ($.cookie(‘pop’) == null) {
            $(‘#dddd’).modal(‘show’);
            $.cookie(‘pop’, ’7');
        }
    });
</script>

Upvotes: 1

Related Questions