blueimp/jQuery-File-Upload — Issue #811: Using Progress/Progressall or start/Stop to stop user from leaving page before upload is complete
Author: philmccarty
Created: 2011-11-24 06:23:56+00:00
State: open

Hi.

First - I love this plugin. It's fantastic. Thank you for all the time and energy you've put into it, it shows. It is a very robust and well written piece of software. And thanks for being patient enough to answer the hundreds (nearly thousands) of questions that are thrown your way for a free piece of software.

Second - I'm interested in configuring my page so that it prevents the user from leaving the page while an upload is in progress. My best guess is to modify a variable during Start, and then turn it off during stop, and then check to see if that variable has been set during "beforeunload."

My second best guess is to check the Progress/ProgressAll, and if it's 0, or 100, allow the person to leave, but if it's in between, stop them (also on beforeunload)

I'm pretty new to Javascript and Jquery, so I'm not sure how to do these things without inadvertently overriding the default activity of fileupload, can I just set a global variable "upload_in_progress"

$('#fileupload').bind('fileuploadstart', function (e,data){
upload_in_progress = true;

$(''#fileupload').bind('fileuploadstop', function (e,data) {
upload_in_progress = false;
}

$(window).bind('beforeunload', function (){
if (upload_in_progress == true)
{
return "Leaving now would abort your upload. Are you sure?";
}
}

Or something to that effect?