10

Is it possible to cancel file upload that uses hidden iframe?

I've tried to set source of iframe to empty string, but upload haven't been interrupted.

Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197

4 Answers4

8

the iframe is the transport channel that is carrying the form posting, so Atanas is correct, you have to stop the transport inside the iframe.

here is a way of doing it depending on browser:

if (iframeObj.contentWindow.document.execCommand)
    { // IE browsers
        iframeObj.contentWindow.document.execCommand('Stop');
    }
else
    { // other browsers
        iframeObj.contentWindow.stop();
    }
// notify user upload was cancelled, remove spinner images, etc
Steve Wasiura
  • 768
  • 1
  • 8
  • 19
2

Try this:

iframe.contentWindow.stop(); //for anything but IE
iframe.contentWindow.document.execCommand("Stop"); // for IE
Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
1

Currenty setting iframe src to "javascript:false" works for me.

Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197
0

I'm not sure but i guess removing the iframe from the dom should be enough?