views:

409

answers:

2

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.

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 (hidden's only attribute is display:none;):

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

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;

And the content of notifyLoaded:

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

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.

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

A: 

Here's an example that works for me, without Firebug open (tested in FF 3.6.2 Mac): http://www.jsfiddle.net/Kukry/

I'm using the jQuery .load() event instead of onload.

var iframe = $("<iframe/>").load(function () {
    alert("loaded");
}).attr({
    src: "http://code.jquery.com/jquery-1.4.2.min.js"
}).appendTo($("#thediv"));

Note that I'm loading a JavaScript file, not an audio file, so that might make a difference.

bcherry
As stated above in the comment, with the audio file I have gotten everything to work (with Firebug not just closed but disabled, with Firebug enabled it always works) by setting an onload in the code and also touching the content doc. Thanks for your suggestion, but using jQuery's load function did not work - I tried it multiple times.I am still looking for an explanation as to why setting the onload in the contentDocument of the iFrame made everything work. My best guess is that it caused the load event to be triggered because something was set in the contentDocument.
justkt
+1  A: 

Maybe you call some Firebug internal function, like console.log(), somewhere? In that case, Firefox will threw an exception which can stop the execution if Firebug is not active.

Johan
See edit. I did not use console.log.
justkt