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

89
Views
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 answers
Answer question

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 Report
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!