How to create a cookie for popup ads to open 1 time only 24 hours

0

I need help with my site. I use the popup format to modernize my website, but I gain the first time it is displayed for the same user in the 24 hour period ... Only this popup is being opened 4,5 and you 6 times for the same one user. I would like to know if you have a javascript cookie for this advertising to open once only every 24 hours.

For those who want to take a look at my site is this one: www.filmestorrentslife.com

    
asked by anonymous 10.02.2016 / 08:29

1 answer

1

You can use these functions to help you create, read, and delete cookies

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

In your case just use it in more or less this way:

var x = readCookie('visualizou_popup')
if (x) {
    // achou o cookie não mostra pop up
} else {
    // mostra popup e cria cookie
    createCookie('visualizou_popup', 'true', 1);
}
    
10.02.2016 / 12:16