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

134
Visualizações
¿Cookie sigue siendo HttpOnly de manera predeterminada cuando no está configurado para hacerlo?

Estoy tratando de agregar temas simples a mi sitio web. Se supone que el script crea una cookie de tema para ver qué tema se usa y luego aplica el estilo. Solía funcionar, pero ahora se configura en httpOnly (lo que significa que JS no puede cambiarlo, incluso si JS lo crea). Se establece en http solo verdadero, incluso si trato de configurarlo específicamente en falso, lo que me impide cambiarlo. Aquí está el código:

 // Themes var numOfThemes = 2; var theme = 0; // Standart getCookie function copied from w3schools function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } // This function sets the theme depending on the value inside the theme cookie (eg.: "theme=3") function applyTheme() { var cookie = parseInt(getCookie("theme")); var hs = document.getElementsByTagName('style'); if(hs.length > 1); for (var i=0, max=hs.length; i < max; i++) { hs[i].parentNode.removeChild(hs[i]); } switch(cookie) { case 0: theme = 0; break; case 1: theme = 1; var style = document.createElement('style'); style.innerHTML = ``; document.head.appendChild(style); break; //... } } // This is supposed to set the cookie inside the browser. I tried adding HttpOnly=false; at the end but it doesn't change anything function setTheme(theme) { const d = new Date(); d.setTime(d.getTime() + (365*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); document.cookie = "theme=" + theme + ";" + expires + ";path=/;SameSite=Lax;"; } // this is the function for switching the theme on a button click function themeSwitch() { var theme = + parseInt(getCookie("theme")) + 1; if(theme > 4) { theme = 0; } setTheme(theme); } applyTheme();
about 4 years ago · Juan Pablo Isaza
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