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

Đinh Hồng Châu picture Đinh Hồng Châu · May 25, 2011 · Viewed 24.4k times · Source

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!

Answer

Dan picture Dan · Jun 5, 2011

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.