【发布时间】:2014-09-18 12:13:26
【问题描述】:
我在 HTML 页面中使用隐藏的 iframe 进行下载。我想知道它什么时候完成。我在网上搜索了很多,每个人都说我应该使用 iframe 的 onload 事件处理程序,但它在 Chrome 中不适合我!
我不确定在哪里,但我在某处读到这是因为我使用 iframe 而不是 HTML 文档下载文件。而且我必须承认它是 Chrome 特有的,并且在 FireFox 中运行良好。
我还测试了readstate 和onreadystatechange,但均未成功。
我创建了一个小提琴来演示这个问题:
function download(url)
{
var iframe = document.createElement("iframe");
iframe.src = url;
iframe.onload = function () {
console.log('Download completed.');
};
document.body.appendChild(iframe);
}
<button onclick="download('http://www.colorado.edu/conflict/peace/download/peace.zip');">Download</button>
【问题讨论】:
标签: html google-chrome iframe onload