如何阻止iframe加载?

noo*_*oob 4 javascript iframe upload jquery

嗨,我正在通过iframe上传文件.

HTML:

<from action="upload.php" target="iframe">
    <input type="file" name="file" />
    <input type="submit" />
</form>
<iframe name="iframe" src="javascript:false;"></iframe>
Run Code Online (Sandbox Code Playgroud)

现在我想在上传时中止上传.所以我想停止iframe加载.

我试过的

$("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");
Run Code Online (Sandbox Code Playgroud)

所有函数都不会抛出错误但过了一段时间我取消的文件显示在上传文件夹中.这就是奇怪的事情.

有什么建议?

Ror*_*san 9

虽然您可以破坏iframe元素,但它所做的任何HTTP请求都无法取消.这是HTTP的设计.

最接近的类比是,它就像试图通过摧毁枪来阻止你发射的子弹.