1

I'm using dropzone to upload files but I want to prevent the page unload during upload. How can I do to sync dropzone with a window.onbeforeunload?

Tobia
  • 9,165
  • 28
  • 114
  • 219

2 Answers2

1
$(window).bind('beforeunload', function() {
    var dz=$("#my-dropzone")
    if (dz.length && dz[0].dropzone && dz.dropzone.getUploadingFiles().length>0){
        return 'Warning...';
    }
}); 
Tobia
  • 9,165
  • 28
  • 114
  • 219
1

you have to stop submit form until all the file is uploaded in dropzone

var submitfiles = false;
var submitButton = document.querySelector("#submit");
submitButton.addEventListener("click", function (file) {

    if (myDropzone.getAcceptedFiles().length > 0) {
        if (submitfiles === true) {
            submitfiles = false;
            return;
        }

        file.preventDefault();
        myDropzone.processQueue();

        myDropzone.on("complete", function () {
            submitfiles = true;
            $('#submit').trigger('click');
        });
    } 
});
Jenish
  • 535
  • 4
  • 16