How to stop iframe loading?

2019-02-23 18:42发布

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?

2条回答
叛逆
2楼-- · 2019-02-23 19:12

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.com/demos/. Of course they have a bit complicated implementation.

查看更多
戒情不戒烟
3楼-- · 2019-02-23 19:22

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.

查看更多
登录 后发表回答