views:

10

answers:

0

I've got a web application that allows asynchronous upload of large files using SWFUpload. But if the user tries to navigate to a different page while an upload is in progress (by clicking a link, say) the browser waits until the upload completes before it actually goes to that page. Is there some way to make navigation automatically cancel all current uploads?

The logical workaround would be to add code to window.onbeforeunload to cancel the upload, however this does not work for me as I'd like to actually use that event, and only cancel the current upload if the user chooses to navigate away from the page. Since there's no callback for a user choosing to continue navigation (please correct me if I'm wrong), I'm not sure how to progress.

Desired behavior:

  1. User begins uploading a large file
  2. User clicks a link on the page
  3. A navigation dialog appears asking if they're sure they want to leave the page

    4a. If the user chooses to continue, the upload is canceled and the navigation occurs immediately

    4b. If the user chooses to stay on the current page, the upload continues normally

I'm using IE 8.0.6001.18702 and Flash 10.1.85.3. This might be an IE-specific issue, but unfortunately I must support it. Is there any way to get SWFUpload to behave like this?

The only thing I can come up with is along these lines:

window.onbeforeunload = function()
{
   setTimeout(function()
   {
      // Although this is a terrible solution, if I could somehow check if the
      // browser has a pending navigation at this point I could conditionally
      // cancel the uploads. However, I don't know how to do this and I'm not
      // not even sure if it's possible.

      alert("Well, this doesn't help much.");
   }, 100);

   return "BE SURE OF YOURSELF";
}

related questions