Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
La cookie no se guarda

Chicos, estoy tratando de captar algo de la pantalla (correo electrónico) cuando se abre el formulario y luego guardarlo en la cookie para poder usarlo después de cerrar el formulario y mostrarlo en otro lugar. Escribí este código. ¡Espero que sea lo suficientemente limpio como para ser entendido! Todo funciona excepto que no se guarda en la cookie 🍪 aquí está el código:

 //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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!