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

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