仅显示一次jQuery弹出窗口 [英] Show Jquery Popup Only Once

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

问题描述

我有一个网站,用户必须在该网站上登录,完成该操作后,他们将被定向到新页面,并显示一个弹出框.我没有问题显示弹出框,但是如果您刷新页面,则会出现弹出框.我希望它只在他们登录后才显示,并且只要他们永不退出,就不会再显示.这意味着,如果他们重新刷新页面或类似的弹出窗口,将不会再次出现.是否有某种插件或简单的代码(我是Jquery的初学者)?

I have a site where a user must login and once that is done they are directed to a new page and a pop up box appears. I have no problem displaying the popup box however if you refresh the page over and over the popup box appears. I want it to display only once they login and never again after that as long as they never sign out. This means if they re-fresh the page or anything like that the popup will NOT appear again. Is there some sort of plugin or easy code for this (I'm kind of a beginner in Jquery)?

<div id="popup-image-back">
    <div class="popup-textbox">
        <div class="textbox-title">WE’VE HAD A MAKEOVER!</div>
        <div class="textbox-p">With fewer restrictions, more destinations and even better rewards you can start saving more money!</div>
    </div>
    <img class="new-popup-xclose" src="images/close-x-dark.png" />
</div>
<div id="back-wrapper"></div>

JavaScript

JavaScript

$(document).ready(function () {
    $('#back-wrapper').fadeIn(1000, function () {
        $('#popup-image-back').fadeIn(1000);
    });
    $(".new-popup-xclose").click(function () {
        $('#popup-image-back').fadeOut(1000);
        $('#back-wrapper').fadeOut(1000);
    });
});

推荐答案

尽管此线程可能很古老,但我想给出一个OP可以使用的答案.通过使用cookie,可以将页面设置为仅显示一次.由于大多数浏览器都支持cookie,因此这比使用当前浏览器拥有的内部存储引擎更可靠.

While this thread may be ancient, I wanted to give an answer that OP could have used. By using cookies, you can set the page to only show once. Since most browsers support cookies, this is more reliable than using the internal storage engine that current browsers possess.

$(document).ready(function(){

    // test for cookie here
    if ($.cookie('test_status') != '1') {
        //show popup here
        window.open('YOUR POPUP URL HERE','windowtest','toolbar=0,status=0,width=500,height=500');

        // set cookie here if not previous set
        var date = new Date();
        var minutes = 30;
        date.setTime(date.getTime() + (minutes * 60 * 1000));
        $.cookie('test_status', '1', {expires: date});
   }

});

要对此进行测试,请确保在每次刷新之间清除cookie.

To test this, be sure to clear your cookies between every refresh.

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

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