1

I'm using jQuery to initiate the download of large files via an iframe (so as not to lock up the browser). If I remove that iframe from the DOM in FF the save dialog will not appear since the window that initiated it no longer exists. However, in IE, even when I remove the iframe from the DOM the process of downloading continues, and the save dialog will eventually appear. The code looks a little like this:

To add:

$("#my-id").append("<iframe id='my-iframe' src='my.zip' style='visibility:hidden' />");

To remove:

$("#my-iframe").remove();

I read something about contentWindow.execCommand in IE, but there is no command identifier that works to "stop" the processing of a URL.

  • 1
    Side-question: Why do this in an iframe instead of via ajax? – Jonathan M Jun 18 '12 at 15:43
  • It is my understanding that you can't get a download via Ajax. These are compressed ZIP files with content-dispostion as attachment. –  Jun 18 '12 at 15:47
  • Anything that is retrievable via http can be done with an ajax call, since an ajax call is just an http request. – Jonathan M Jun 18 '12 at 15:48
  • 1
    @JonathanM: You can't trigger a browser's "Download file" dialog/functionality using an Ajax request. – thirtydot Jun 18 '12 at 15:52
  • That's a good point, @thirtydot. Forgot he was downloading to disk (instead of for display in the browser). – Jonathan M Jun 18 '12 at 16:36

2 Answers2

3

wasn't cancel, wasn't close.. but stop ;)

from Javascript: Cancel/Stop Image Requests

//cancel image downloads
if(window.stop !== undefined) 
{
  window.stop();
}
else if(document.execCommand !== undefined)
{
  document.execCommand("Stop", false);
}
Community
  • 1
  • 1
Arcadien
  • 2,198
  • 14
  • 26
  • I figured out what the issue was. I was trying to call similar code on the iframe itself, but the main window apparently is still handling the download, so calling on the document worked. Too bad the MSN developer network doesn't cover this. Thanks. –  Jun 21 '12 at 19:22
0

Use ajax, it will allow you to cancel the request (even in your iframe, i guess). see Abort Ajax requests using jQuery

Community
  • 1
  • 1
Arcadien
  • 2,198
  • 14
  • 26
  • mm seen your last comment. What happens if you cancel() the iframe window? – Arcadien Jun 18 '12 at 15:52
  • I'm guessing you meant close(). I've tried that as well, and although the close() executes successfully it does not cancel the download. –  Jun 18 '12 at 15:58
  • You can't abort an Ajax request that doesn't exist for an iframe source attribute. –  Jun 18 '12 at 16:04