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

290
Views
¿Cómo mantengo el estado de la casilla de verificación para la ventana emergente del complemento de Firefox?

Estoy tratando de hacer un interruptor de palanca basado en una casilla de verificación. La casilla de verificación solo debe cambiar cuando el usuario cambia el interruptor.

Aquí está mi código JavaScript:

 var toggle = false; document.getElementById("toggle").onclick = function () { if (this.checked == true) { toggle = true; document.getElementById("toggleText").textContent = "ENABLED"; browser.browserAction.setIcon({ path: "/icons/icon.png" }); } else { document.getElementById("toggleText").textContent = "DISABLED"; browser.browserAction.setIcon({ path: "/icons/icon-inactive.png" }); } };

Sin embargo, el estado de la casilla de verificación siempre está desactivado cuando vuelvo a abrir la ventana emergente. ¿Alguna idea sobre cómo puedo lograr hacer esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Guarde el estado en el almacenamiento local. He aquí un ejemplo simplificado:

manifiesto.json:

 { "manifest_version": 2, "name": "Save states", "version": "1.0.0", "browser_action": { "default_title": "States", "default_popup": "index.html" } }

índice.html:

 <html> <head> </head> <input type="checkbox" id="checkbox"> checkbox <script src="index.js"></script> </html>

índice.js:

 const checkboxStorageState = JSON.parse(localStorage.getItem("checkboxStorageState")); const check = document.getElementById("checkbox"); let currentState = false; if(checkboxStorageState) { currentState = checkboxStorageState; check.checked = currentState; } check.onclick = function() { if(this.checked) { currentState = true; } else { currentState = false; } localStorage.setItem("checkboxStorageState", JSON.stringify(currentState)); }
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!