Hi I'm uploading a file through an iframe.
HTML:
<from action="upload.php" target="iframe">
<input type="file" name="file" />
<input type="submit" />
</form>
<iframe name="iframe" src="javascript:false;"></iframe>
Now I would like to abort the upload while uploading. So I would like to stop the iframe loading.
What I've tried
$("iframe").attr("src", "javascript:false;");
$("iframe").remove();
if (typeof(window.frames[0].stop) === "function")
window.frames[0].stop();
else
window.frames[0].document.execCommand("Stop");
All functions don't throw an error but after a while the file I've canceled was displayed in the upload folder. So that's the weird thing.
Any suggestions?
Hi I'm uploading a file through an iframe.
HTML:
<from action="upload.php" target="iframe">
<input type="file" name="file" />
<input type="submit" />
</form>
<iframe name="iframe" src="javascript:false;"></iframe>
Now I would like to abort the upload while uploading. So I would like to stop the iframe loading.
What I've tried
$("iframe").attr("src", "javascript:false;");
$("iframe").remove();
if (typeof(window.frames[0].stop) === "function")
window.frames[0].stop();
else
window.frames[0].document.execCommand("Stop");
All functions don't throw an error but after a while the file I've canceled was displayed in the upload folder. So that's the weird thing.
Any suggestions?
Share Improve this question asked Mar 12, 2012 at 14:36 noobnoob 9,2124 gold badges39 silver badges65 bronze badges 1-
window.stop
cancels any further resource loading but not the original request: developer.mozilla/en-US/docs/Web/API/Window/stop – Jānis Elmeris Commented Jul 5, 2023 at 11:23
2 Answers
Reset to default 9While you can destory the iframe
element, any HTTP requests it has made cannot be cancelled. This is by design of HTTP.
The closest analogy is that it's like trying to stop a bullet you've fired by destroying the gun.
Try flash uploaders. They have many advantages against standard uploading input, like multiple file upload, stopping upload queue, file size limit etc. Try a demo here: http://www.uploadify./demos/. Of course they have a bit plicated implementation.