I'm using a hidden iframe in an HTML page for downloading purposes. And I would like to know when it's done. I've searched the Internet a lot and everyone says that I should use iframe's onload
event handler but it's not working for me in Chrome!
I'm not sure where but I read somewhere that it's because I'm downloading files with my iframe instead of HTML documents. And I must admit that it's specific to Chrome and it works fine in FireFox.
I've also tested readstate
and onreadystatechange
without success.
I've created a fiddle to demonstrate the problem:
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>