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

查看:23
本文介绍了仅显示一次 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

$(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,您可以将页面设置为仅显示一次.由于大多数浏览器都支持cookies,这比使用当前浏览器拥有的内部存储引擎更可靠.

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天全站免登陆