Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
Alternar hojas de estilo externas con javascrtip y guardar con almacenamiento local

Hola, estoy haciendo esto en un sitio web.

Me gustaría que los cambios no se eliminen cuando se actualiza la página del navegador.

Muchas gracias por su ayuda.

 Html: <link id="change" rel="stylesheet" href="css/style.css"> In javascript: $("#mobile-float").click(function() { return (this.tog = !this.tog) ? addZonaDesk() : showZonaDesk(); }); function addZonaDesk(){ document.getElementById("style").href = "css/style.css?t=143"; } function showZonaDesk(){ document.getElementById("style").href = "css/style1.css?t=143"; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

 // Get link element and the button let link = document.getElementsByTagName('link')[0]; let btn = document.getElementById('btn'); // Save href values let val1 = "css/style.css?t=143"; let val2 = "css/style1.css?t=143"; // Temp variable (just for checking) let swapped = true; // Pass the path to the function const toggleDesk = (path) => { // Set href link.href = path; // Save in the local storage localStorage.setItem("myLink", path); }; // Toggle link path values (for testing) btn.addEventListener('click', () => { swapped == false ? [toggleDesk(val1), swapped = true] : [toggleDesk(val2), swapped = false]; }); // Window onload: window.addEventListener('load', () => { // Check browser support for local storage if (typeof(Storage) !== "undefined") { // If there's a value saved, get it and set the link path if(localStorage.getItem("myLink")) { let path = localStorage.getItem("myLink"); link.href = path; } } });
 <!-- Note: add [type="text/html"] --> <link type="text/html" rel="stylesheet" href="css/style.css"> <button id="btn">Click here</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda