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

倾然丶 夕夏残阳落幕 提交于 2019-11-30 00:24:17
Dan

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!