rolando.pdl
rolando.pdl

Reputation: 51

Jquery cookie plugin for popup message

I have a message that pops up when a user first visit my homepage. I'm trying to make that the message doesn't pop up if you have visited the page within the last 15 days. I'm thinking on using the jquery.cookie plugin to achieve that but not sure exactly how to use it. Any help will be greatly appreciated.

I'm using the colorbox plugin for my popup message, here is the code:

$(function () {
    $(window).bind('load',
    function (e) {
        window.setTimeout(function () {
            $.colorbox({ opacity: 0.3, href: "popupQualify.aspx" });
        }, /*timeout->*/2000);
    });
});

Upvotes: 0

Views: 735

Answers (2)

JAAulde
JAAulde

Reputation: 19560

Check for the cookie, show the popup if it is not present. Then set the cookie with expiration of 15 days.

$(function () {
    if($.cookie('nopopup') === null)
    {
        window.setTimeout(function () {
            $.colorbox({opacity: 0.3, href: 'popupQualify.aspx'});
        }, 2000);
    }

    $.cookie('nopopup', 'true', {expires: 15});
});

Upvotes: 1

Majid Shahmohammadi
Majid Shahmohammadi

Reputation: 377

you can use this function :

function getCookie(c_name){
            var i,x,y,ARRcookies=document.cookie.split(';');
            for (i=0;i<ARRcookies.length;i++)
              {
              x=ARRcookies[i].substr(0,ARRcookies[i].indexOf('='));
              y=ARRcookies[i].substr(ARRcookies[i].indexOf('=')+1);
              x=x.replace(/^\s+|\s+$/g,'');
              if (x==c_name)
                {
                return unescape(y);
                }
              }
        };
        function setCookie(c_name,value,exdays){
            var exdate=new Date();
            exdate.setDate(exdate.getDate() + exdays);
            var c_value=escape(value) + ((exdays==null) ? '' : '; expires='+exdate.toUTCString());
            document.cookie=c_name + '=' + c_value;
        };

Upvotes: 0

Related Questions