1

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')
    });
  • 1
    You can store a flag in the localStorage after you've shown the modal, and show it only if that flag hasn't been set yet – Alon Eitan Dec 29 '15 at 17:48
  • 1
    Could use a cookie or session which is set to true on first visit, then each load checks if that cookie exists. – eselskas Dec 29 '15 at 17:51
  • Both of these are good ideas, just keep in mind that the user can clear their cookies / localstorage and then they'll see the modal again – taylorc93 Dec 29 '15 at 17:53

2 Answers2

1

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>
Community
  • 1
  • 1
0xburned
  • 2,625
  • 8
  • 39
  • 69
0

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