Handle cookie for Popup

0
Hello, I'm trying to make a popup, I've already set up its structure, I just need to validate it so that it does not open all the time I visit the page, I'm trying to use a cookie, I do not know if my code is conflicting with wp or is wrong.

<script>
function setCookie(name,exdays){    //função universal para criar cookie
var expires;

var date; 

var value;
date = new Date(); //  criando o COOKIE com a data atual
date.setTime(date.getTime()+(exdays*24*60*60*1000));
expires = date.toUTCString();
value = "TESTE123";
document.cookie = name+"="+value+"; expires="+expires+"; path=/";
}

function getCookie(){
var c_name = document.cookie; // listando o nome de todos os cookies
    if(c_name!=undefined && c_name.length > 0){ // verificando se o mesmo existe
    var posCookie = c_name.indexOf(cookieSeuNome); // checando se existe o cookieSeuNome 
        if (posCookie >= 0){ //se existir o cookie mostra um alert no browser
        document.getElementById('Home_PopBg').style.display = 'none';
        }else{}
    }
}

</script>
    
asked by anonymous 23.08.2017 / 20:06

1 answer

0

I could not use Js, I did it with php. If someone needs the following:

<?php
$nome = "popupNews2";
$valor = "style=display:none;";
$expira = time() + 24*3600;
setcookie($nome, $valor, $expira);
$ler = $_COOKIE['popupNews2'];
?>

<section id="Home_PopBg" class="Home_PopBg2" <?php echo $ler; ?>>
    
24.08.2017 / 15:40