Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which JS event is fired when Chrome gets the download file?

I am having a problem with onLoad event of an iframe on Google Chrome. I created an iframe and set value for its "src" attribute to get a file from server. While server is processing, a waiting box is displayed until client gets the returned file. I tried to use the onLoad event of iframe to detect when client get the file to turn off that waiting box, but on Google Chrome that event handler does not work.
With Firefox, when client gets a file, a "Save to" popup will be displayed automatically and event "load" will be fired, but this is not happen on Chrome.
Could you please tell me how to handle this issue? Thank you so much!

like image 839
Đinh Hồng Châu Avatar asked May 25 '11 15:05

Đinh Hồng Châu


People also ask

Where do Chrome downloads fail to?

Google Chrome has a built-in download manager to display all your downloads, whether it's active, failed, canceled, or completed. Press Ctrl + J or click the Options dropdown menu and select Downloads to open the download manager. In the list of downloads, find the failed item and click Resume.

How do you see what you're downloading on Chrome?

Display Your Chrome Downloads Alternatively, you can use the "My Downloads" keyboard command. Press Ctrl + J (hold down the Ctrl key and the J key at the same time) to accomplish the same result and display the download list.


1 Answers

I've run into this exact issue. It turns out Chrome triggers absolutely no events in an iframe upon a file download.

Since there are no events to look out for and you're returning a file (as apposed to any inline content) the workaround I was forced to inspect the contents of the iframe after a few seconds, if it is empty then assume there were no errors and the results were processed correctly. If it contains data (my server will return JSON if there are any errors) then handle the error data accordingly.

like image 186
Dan Avatar answered Oct 04 '22 13:10

Dan