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

160
Views
JavaScript when navigating away from the page confirm whether to loose upload

I am making a file uploader, and if the user submit the navigates away from the page before the file uploading is complete, I wish to tell ask them if they are sure they wish to navigate away and loose thier upload.

In Chrome however it blocks the alert during beforeunload: Blocked alert('....') during beforeunload.

function confirmLooseUpload() {
    if (THIS.getAttribute('uploading') == "progress" ) {        
        return !alert("Wait for upload to complete? Press cancel to abort upload and navigate away now")
    }
}
window.addEventListener('beforeunload', confirmLooseUpload)

I research the issue and there is sendBeason, and it seems to be for small data, not a 10MB upload. Also most hits detail how to abort a fetch POST, rather than how to ensure it finishes.

Some solutions like this suggest just return a string seems to cancel the unload event, but it did not work for me:

function confirmLooseUpload(event) {
    if (THIS.getAttribute('uploading') == "progress" ) {
        return "There is a file upload in progress, please wait for it to finish..."
    }
}
window.addEventListener('beforeunload', confirmLooseUpload)

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!