每个用户只显示一次弹出窗口 [英] Display A Popup Only Once Per User

查看:34
本文介绍了每个用户只显示一次弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经有了答案,但我仍然不确定它到底是如何工作的.

我在 footer.php 中使用以下 HTML:

以及以下 Javascript:

$j(document).ready(function() {$j("#popup").delay(2000).fadeIn();$j('#popup-close').click(function(e)//您正在点击关闭按钮{$j('#popup').fadeOut();//现在弹出窗口是隐藏的.});$j('#popup').click(function(e){$j('#popup').fadeOut();});});

一切都很好,但我只想向每个用户显示一次弹出窗口(可能使用所有论坛帖子都在讨论的 cookie 内容)但我不知道如何将其合并到上面的 JS 中.

>

我知道我必须在我的页脚中加载 cookie JS:

<script type="text/javascript" src="scripts/jquery.cookies.2.2.0.min.js"></script>

但这就是我所理解的,谁能告诉我添加了 cookie 的 JS/jQuery 应该是什么样子?

谢谢

詹姆斯

解决方案

*注意:当数据存储在浏览器内存中时,这将在每个浏览器中显示一次弹出窗口.

尝试 HTML localStorage.

方法:

  • localStorage.getItem('key');
  • localStorage.setItem('key','value');

$j(document).ready(function() {if(localStorage.getItem('popState') != '显示'){$j('#popup').delay(2000).fadeIn();localStorage.setItem('popState','shown')}$j('#popup-close, #popup').click(function()//您正在点击关闭按钮{$j('#popup').fadeOut();//现在弹出窗口是隐藏的.});});

工作演示

There have already been answers to this question but I am still unsure exactly how it works.

I am using the following HTML in my footer.php:

<div id="popup">
    <div>
        <div id="popup-close">X</div>
            <h2>Content Goes Here</h2>
    </div>
</div>

and the following Javascript:

$j(document).ready(function() {
    $j("#popup").delay(2000).fadeIn();
    $j('#popup-close').click(function(e) // You are clicking the close button
    {
    $j('#popup').fadeOut(); // Now the pop up is hiden.
    });
    $j('#popup').click(function(e) 
    {
    $j('#popup').fadeOut(); 
    });
});

Everything works great, but I want to only show the pop up once per user (maybe using the cookie thing all the forum posts go on about) but I do not know exactly how to incorporate it into the JS above.

I know that I will have to load the cookie JS in my footer with this:

<script type="text/javascript" src="scripts/jquery.cookies.2.2.0.min.js"></script> 

But that is all I understand, can anyone tell me exactly how the JS/jQuery should look with the cookie stuff added?

Thanks

James

解决方案

*Note : This will show popup once per browser as the data is stored in browser memory.

Try HTML localStorage.

Methods :

  • localStorage.getItem('key');
  • localStorage.setItem('key','value');

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

    $j('#popup-close, #popup').click(function() // You are clicking the close button
    {
        $j('#popup').fadeOut(); // Now the pop up is hidden.
    });
});

Working Demo

这篇关于每个用户只显示一次弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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