Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Cookie not Saving

Guys I am trying to catch something form the screen (email) when the form is opened & then save it in the cookie so I can use it for after the form is closed & show it somewhere else! I wrote this code. I hope its clean enough to be understood! Everything is working except that it is not saving in the cookie 🍪 here is the code:

//singelton works always
let start = isFormOppened();

while (start) {
  if (isFormOppened && doesEmailInputExist && getBtn) {
    console.log('code works');
    getBtn().addEventListener('click', (e) => {
      setCookie('email', getEmailValue(), 1);
      console.log('cookie saved successfully');
      start = false;
    });
  }
}

function isFormOppened() {
  if (!document.querySelector('.cb-hp__wrapper')) {
    return false;
  }
  return true;
}

function doesEmailInputExist() {
  if (!document.querySelector('#email', '.cb-text__control')) {
    return false;
  }
  return true;
}

function getBtn() {
  if (document.querySelector('button', '.cb-button')) {
    return document.querySelector('button', '.cb-button');
  }
}

function getEmailValue() {
  if (!document.querySelector('#email', '.cb-text__control')) {
    return -1;
  }
  return document.querySelector('#email', '.cb-text__control').value;
}

function setCookie(name, value, days) {
  var expires = '';
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
    expires = '; expires=' + date.toUTCString();
  }
  document.cookie = name + '=' + (value || '') + expires + '; path=/';
}

function getCookie(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) {
  document.cookie =
    name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda