rudrainnovative rudrainnovative - 1 month ago 21
jQuery Question

Show jQuery popup only at first visit of a page

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.

Still I am using this, but I don't know how to hide at the second time:

var isshow=0;
$(document).ready(function() {
if (isshow == 0) {
$('#jPopup').show();
}
isshow = 1;
});


But the ishow variable initializes every time.

Answer

You can use localstorage. It is easy to understand and use.

$(document).ready(function() {
    var isshow = localStorage.getItem('isshow');
    if (isshow== null) {
        localStorage.setItem('isshow', 1);

        // Show popup here
        $('#jPopup').show();
    }
});

It will show you the popup at first visit of your site.