D
D
djienbaev972020-09-08 09:27:09
JavaScript
djienbaev97, 2020-09-08 09:27:09

How to automatically open modal window only once?

Hello! On my site, when visiting, a modal window automatically opens, to select the language there are two links there simply. How can I make this modal window open only once? Only on the first visit? Not every time the page is refreshed

<div class="modal fade in" id="myModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <a href="">
                        <button type="button" class="btn btn-primary">RU</button>
                    </a>
                    <a href="/en/">
                        <button type="button" class="btn btn-primary">EN</button>
                    </a>
                </div>
                <div class="modal-footer">
                </div>
            </div>
        </div>
    </div>


And the script
$(window).on('load',function(){
        $('#myModal').modal('show');
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2020-09-08
@djienbaev97

$(window).on('load',function(){
        if (!localStorage.getItem('myModal') {
              $('#myModal').modal('show');
              localStorage.setItem('myModal' , true)
        }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question