如何检测隐藏的iframe是否已加载?

时间:2017-01-06 09:17:13

标签: javascript html iframe

我有一个简单的HTML / JS:

<form method="post" enctype="multipart/form-data" action="Service.ashx" target="download" id="uploadForm">
    <label for="x">Select file:</label> <input type="file" name="x" id="x" /> <button type="submit">Generate</button>
</form>
<iframe style="display: none" name="download" id="frmDownload"></iframe>
<script type="text/javascript">
    document.getElementById("frmDownload").onload = function () {
        alert("Yay!");
    }
</script>

简而言之,有一个小<form>提交隐藏的<iframe>。成功后,Service.ashx将返回文件下载:

content-type: application/zip
content-disposition: attachment; filename="result.zip"

此过程可能需要一段时间(一两分钟),因此我想向用户显示“请稍候,仍在处理”。当过程完成并且文件可供下载时,我想显示“All done!”。不幸的是onload脚本似乎没有被调用(我在Windows上使用最新的Chrome)。有什么建议怎么做?

已添加: A-ha!这是一个Chrome问题!并且专门寻找Chrome,看起来已经被覆盖了:Which JS event is fired when Chrome gets the download file?

嘿,我第一次接近投票给自己的话题! :)

0 个答案:

没有答案
相关问题