Skip to content
Advertisement

how to display js 1 time a day?

I have a code show popup on the website, I want this popup only show 1 once/day for user. I use the code below to show the popup:

For functions theme flatsome:

    function img_popup(){;?>
    <div class="btn-popup">
    <div class="before-img"></div>
    <div class="img-popup">
        <a href="">
            <img src="link-images">
        </a>
    </div>
    </div>
<?php }
add_action('flatsome_footer','img_popup');

For js:

<script>
    jQuery(document).ready(function ($) {
        function show_popup(){
            $(".btn-popup").show();
       };
       window.setTimeout( show_popup, 5000 ); // 5 seconds
        $(".btn-popup .before-img").on("click", function(e){
            $(".btn-popup").addClass('hide-imt');
     
        });
    });
    </script>

Please help me, thanks.

Advertisement

Answer

if (!localStorage.getItem("lastSet")) {
//  your logic here 
  localStorage.setItem("lastSet", new Date().getTime())
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement