Question

I was recently helped with this issue, but cannot get hold of the person who helped me.

The code bellow makes a popup show every 24 hours and creates a cookie that expires every day. The issue I'm having is that when the cookie expires, a new one is created but the popup box does not show. I have this running on a site with a lot of users and all say it popped up once and never again.

I'm fine with HTML & CSS but this is 100% out of my range. I think the cookie needs to be deleted not renewed from what I have seen around the internet, but I'm expecting to be wrong.

Any help would be greatly appreciated! Many thanks in advance.

        <link rel="stylesheet" href="colorbox.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script src="./colorbox/jquery.colorbox.js"></script>
    <script>
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;
    }
function checkCookie()
{
    var cookieValue=getCookie("IGTop100Vote");
    if (cookieValue==null || cookieValue=="")
    {
      setCookie("IGTop100Vote","IG-Top-100-Vote-Popup-Cookie-24-Hours",1);

   $(".ajax").colorbox({ open:true});


    }
    else{

    }

}
   $(document).ready(function() {


        checkCookie();


    })



    </script>

        <p><a class='ajax' href="./content/ajax.html" title="Vote IG Top 100!"></a</p>
Was it helpful?

Solution

Change your 'if statement' in the checkCookie() function from this

if (cookieValue==null || cookieValue=="")

To this

if (!cookieValue || cookieValue==null || cookieValue=="")

This will check to see if the cookie exists, not just check the value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top