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

107
Views
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
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!