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

110
Vistas
Saving data in localstorage upon close?

I am trying to get values saved in localstorage so that they can persist when the user comes back to the site. Here is what I have:

function saveConfirmation() {
    if (confirm("Are you sure you want to exit? Progress will be saved.")) {
        localStorage.setItem("count", String(count))
    }
}
function saveBeforeUnload() {
    setTimeout(saveConfirmation, 0)
    return "You have unsaved changes"
}

window.onbeforeunload = saveBeforeUnload

When I click out of the tab, Chrome gives a popup asking if I want to leave the page. When I say yes, my other dialogue comes up right as it closes so I can't interact with it. If I say no, my other dialogue comes up and doesn't close when I confirm. How do I get it to where it either 1) Saves when I confirm the popup from Chrome or 2) Get rid of the Chrome popup and save and exit when I confirm my popup?

about 4 years ago · Juan Pablo Isaza
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