How to create cookies for popup advertisements open 1 time only 24 hours

Asked

Viewed 727 times

0

I could use a little help with my website. For a long time I use the popup format to modernize my site, however gain for the first time it is displayed to the same user within 24 hours... Only this popup is being opened 4.5 and te 6 times for the same user. I wonder if you have how to create cookies in javascript for this advertising open a single time every 24 hours.

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

  • Advertising popup? That’s why the use of Adblock is increasing. Telvez placing non-invasively in a strategic place of the site bring more results

  • No doubt the popkit.site is the best alternative. For 3 reasons: Unbranded in the footer of Popup, Free and Customizable. And for your need: Yes, the system has functions to choose the time and amount of views by users. Just add 3 lines of code in the <Head> of your site. I hope you helped.

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 more or less like this:

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);
}
  • First of all thank you very much for the answer, but I am a layman in javascript ... would you edit and put the code ready for me?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.