仅在页面首次访问时显示jQuery弹出窗口 [英] Show jQuery popup only at first visit of a page

查看:240
本文介绍了仅在页面首次访问时显示jQuery弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 jQuery 的新手,我的网站上有一些需求。我只想在用户来时才第一次显示jQuery div弹出窗口。不需要一次又一次地显示。

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;
});

但是ishow变量每次都会初始化。

But the ishow variable initializes every time.

推荐答案

您可以使用localstorage。易于理解和使用。

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.

这篇关于仅在页面首次访问时显示jQuery弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆