开发者

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

开发者 https://www.devze.com 2023-03-08 18:51 出处:网络
I am having a problem with onLoad event of an iframe on Google Chrome. I c开发者_StackOverflowreated an iframe and set value for its \"src\" attribute to get a file from server. While server is proces

I am having a problem with onLoad event of an iframe on Google Chrome. I c开发者_StackOverflowreated 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!


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.


I've run into this same problem and I ended up using this plugin: http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/

It's based on the same concept morgan describes, it's easy to use and and it worked great.


The way I got around this issue was to set a cookie (done = 0) when the page that is going to have the iframe loads, I use javascript to drop the iframe onto the page and I change the value of this cookie when the iframe's source script runs successfully (done = 1).

I then used a simple ajax call with a settimeout to return the value of the cookie, when the value is 1 I can trigger the onload event (that works for all other browsers).

0

精彩评论

暂无评论...
验证码 换一张
取 消