动态创建的iframe用于下载文件触发器onload与firebug但不是没有 [英] Dynamically created iframe used to download file triggers onload with firebug but not without

查看:534
本文介绍了动态创建的iframe用于下载文件触发器onload与firebug但不是没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:由于这个问题现在已经解决了,所以我正在寻找有关信息的原因。对于修复,请参阅我的评论。

EDIT: as this problem is now "solved" to the point of working, I am looking to have the information on why. For the fix, see my comment below.

我有一个Web应用程序,它可以动态地(在超时之后或按照用户的指示)下载wav文件到iframe命令触发默认音频播放器播放它们。应用程序仅针对FF 2或3.为了确定文件何时完全下载,我希望使用iframe的window.onload处理程序。根据此stackoverflow.com answer 我每次都在创建一个新的iframe只要在使用应用程序的浏览器上启用firebug,一切都会很好。没有firebug,onload从不触发。 firebug的版本是1.3.1,而我已经测试过Firefox 2.0.0.19和3.0.7。任何想法,如何可以从iframe的负载可靠地触发wav文件下载?还是有另一种方式来表示完成下载?以下是相关代码:

I have an web application which repeatedly downloads wav files dynamically (after a timeout or as instructed by the user) into an iframe in order to trigger the a default audio player to play them. The application targets only FF 2 or 3. In order to determine when the file is downloaded completely, I am hoping to use the window.onload handler for the iframe. Based on this stackoverflow.com answer I am creating a new iframe each time. As long as firebug is enabled on the browser using the application, everything works great. Without firebug, the onload never fires. The version of firebug is 1.3.1, while I've tested Firefox 2.0.0.19 and 3.0.7. Any ideas how I can get the onload from the iframe to reliably trigger when the wav file has downloaded? Or is there another way to signal the completion of the download? Here's the pertinent code:

HTML(隐藏的唯一属性是display:none;):

HTML (hidden's only attribute is display:none;):

<div id="audioContainer" class="hidden">
</div>

JavaScript(也可以使用jQuery,但innerHTML比html()比我读过的要快):

JavaScript (could also use jQuery, but innerHTML is faster than html() from what I've read):

waitingForFile = true; // (declared at the beginning of closure)
$("#loading").removeClass("hidden");
var content = "<iframe id='audioPlayer' name='audioPlayer' src='" +
    /path/to/file.wav + "' onload='notifyLoaded()'></iframe>";
document.getElementById("audioContainer").innerHTML = content;

并且notifyLoaded的内容:

And the content of notifyLoaded:

function notifyLoaded() {
    waitingForFile = false; // (declared at beginning of the closure)
    $("#loading").addClass("hidden");
 }

我也尝试通过document.createElement创建iframe,但是我发现相同的行为每次使用firebug启动onload时,都不会触发。

I have also tried creating the iframe via document.createElement, but I found the same behavior. The onload triggered each time with firebug enabled and never without it.

编辑:
修正了iframe如何处理的信息声明并添加了回调函数代码。不,没有console.log在这里调用。

Fixed the information on how the iframe is being declared and added the callback function code. No, no console.log calls here.

推荐答案

旧问题,以供将来参考:
就我的经验而言onLoad不被要求下载文件。解决它的一个方法是使用像他们这样做的cookies http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/

Old question but for future reference: As far as my experience onLoad is not called for file downloads. A way to solve it is to use cookies like they do here http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/

这篇关于动态创建的iframe用于下载文件触发器onload与firebug但不是没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆