简体   繁体   中英

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')
    });

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM