简体   繁体   English

灯箱弹出不应再来了

[英]light box popup Should not be come another time

When I load the page the popup should be showed. 当我加载页面时,应显示弹出窗口。 But when I refresh the page the popup should not be there. 但是当我刷新页面时,弹出窗口不应该在那里。 '

       $('body').addClass('stop-scrolling');
       $('#fade').css('display','block');
       $('#light').css('display','block');
    `

fade and light class is for fade the screen and light will slide from upper side. 淡入淡出和淡化等级用于淡化屏幕,光线将从上侧滑动。 Now if I refresh the page this light box will come another time on the screen. 现在,如果我刷新页面,这个灯箱将再次出现在屏幕上。 I have put this code in ready function thats why it shows up every time when I refresh the page.What to do make it shows up only on time at the time of page loading. 我把这段代码放在就绪函数中,这就是每次刷新页面时它出现的原因。要做什么使它只在页面加载时按时显示。 Prevent it to shows up every time I refresh te page. 每次刷新页面时都要防止它出现。 Thanks in advance 提前致谢

Use Something like this 使用像这样的东西

$(document).ready(function () {
    if (localStorage.getItem('wasVisited') !== undefined) {
         $('#fade').hide();
         $('#light').hide();
    } else {
        localStorage.setItem('wasVisited', 1);
         $('body').addClass('stop-scrolling');
         $('#fade').show();
         $('#light').show();
    }
});

You will either have to set a cookie, use Serverside-Code or maybe you could go with session.storage for a plain JS solution. 您将需要设置cookie,使用Serverside-Code,或者您可以使用session.storage来获得普通的JS解决方案。

Here is a example with session storage, with is the best imo: http://fiddle.jshell.net/2Pc58/1/ 这是一个会话存储的例子,是最好的imo: http//fiddle.jshell.net/2Pc58/1/

if(!sessionStorage.getItem("lastVisit")){
         sessionStorage.setItem("lastVisit",new Date());
        alert("you are new here")
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM