Chrome获取下载文件时会触发哪个JS事件

Chrome获取下载文件时会触发哪个JS事件

本文介绍了Chrome获取下载文件时会触发哪个JS事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Chrome上的iframe onLoad事件中遇到问题。我创建了一个iframe并为其src属性设置值以从服务器获取文件。在服务器正在处理时,显示一个等待框,直到客户端获得返回的文件。我尝试使用iframe的onLoad事件来检测客户端何时获取文件以关闭该等待框,但在Google Chrome上,该事件处理程序不起作用。

使用Firefox时,当客户端获取文件时,一个保存到弹出窗口会自动显示,事件加载将被触发,但这不会发生在Chrome上。

请问我该如何处理这个问题?非常感谢!

解决方案

我遇到了这个问题。事实证明Chrome在文件下载时触发​​iframe中绝对没有事件。



由于没有要注意的事件并且您要返回一个文件任何内联内容)解决方法我几秒钟后被迫检查iframe的内容,如果它是空的,则假定没有错误并且结果得到正确处理。如果它包含数据(如果有错误,我的服务器将返回JSON),然后相应地处理错误数据。

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!

解决方案

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.

这篇关于Chrome获取下载文件时会触发哪个JS事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:28