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

108
Visualizações
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 à 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