Show jQuery popup only at first visit of a page

前端 未结 5 945
盖世英雄少女心
盖世英雄少女心 2020-12-14 20:17

I am new to jQuery, and I have some needs on my website. I want to show the jQuery div popup at the first time only when the user comes. No need to show again and again.

5条回答
  •  感动是毒
    2020-12-14 21:00

    You can set a cookie to store a value and check if it is not set then show popup:

    $(document).ready(function() {
        var isshow = $.cookie("isshow");
        if (isshow == null) {
            $.cookie("isshow", 1); // Store
    
            // Show popup here
            $('#jPopup').show();
        }
    });
    

    Or you can set localStorage. Here is a working example. jsFiddle

    $(document).ready(function() {
        if(localStorage.getItem('popState') != 'shown') {
            $("#popup").delay(2000).fadeIn();
            localStorage.setItem('popState','shown')
        }
    });
    

提交回复
热议问题