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

199
Views
¿Cuál es la mejor manera de almacenar las cookies de preferencia del usuario?

Me gustaría permitir a los visitantes que no tienen habilitado el modo oscuro en su dispositivo o navegador una opción de un clic para habilitarlo.

¿Cómo obtengo la cookie actual, la cambio y luego la restablezco antes de la etapa de carga del sitio?

 const currentScheme = () => { var colorScheme = ""; if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { colorScheme = "dark"; } window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => { colorScheme = e.matches ? "dark" : "light"; if(colorScheme !== "dark") { if(document.body.classList.contains("global-hash-dark-version")) { document.body.classList.remove("global-hash-dark-version"); } } else { if(!document.body.classList.contains("global-hash-dark-version")) { document.body.classList.add("global-hash-dark-version"); } } }) return colorScheme; } 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; } let cookieValue = getCookie("choice_settings"); if(cookieValue) { let currentSettings = JSON.parse(cookieValue); if (currentSettings.colorScheme == "dark") { document.body.classList.add("global-hash-dark-version"); console.log("dark") } } else { const temp_scheme = currentScheme(); if (temp_scheme == "dark") { currentSettings = { colorScheme: "dark", ...currentSettings } // This is where I am stuck. // How do I fetch, update, and then reset the cookie with settings? // Other settings will be things like privacy consent and dismissed // notifications // // }
about 4 years ago · Juan Pablo Isaza
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!