Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop iframe loading?

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?

like image 778
noob Avatar asked Feb 22 '23 04:02

noob


1 Answers

While 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.

like image 154
Rory McCrossan Avatar answered Mar 04 '23 20:03

Rory McCrossan