views:

234

answers:

2

I am downloading files through IFRAME method described here:

http://encosia.com/2007/02/23/ajax-file-downloads-and-iframes/

And am showing progress in a div and hiding this div on load completion:

$(objIframe).load(function() {
    $("#spinner").hide();
});

The trouble is, this callback function is never called in Internet Explorer yet it works fine in FireFox. I have added random values to the query request string to avoid caching. Why is the callback not being called?

+1  A: 

Here is my final attempt.

// prepare iframe    
setTimeout(checkReadyState, 100);    

function checkReadyState() {
    if (objIframe.contentWindow.document.readState !== "complete") {
        setTimeout(checkReadyState, 100);
    }
    else {
        $("#spinner").hide();
    }
}
ChaosPandion
See http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/ for some related discussion that might save you some time.
Sorpigal
great article - all good examples that worked in IE - however none of the examples work when pushing a file through Response.Outputstream like described in the article in link on question.
marking as the answer - thanks!! (there are a few typos though). care to explain this solution?
@user210757 - Basically, when you set the `src` property on the `iframe` it will begin to load. Once it has loaded completely the `readyState` property on the `document` will have the value `"complete"`.
ChaosPandion
so you have to poll for this value, there's no event that's fired. awesome solution - thanks for the help
A: 

As far as I know onLoad won't fire if the content is not an HTML document of some kind. At least in my tests it tends to succeed for e.g. text files, html, images, etc, but fail for most other things.

Sorpigal
you're right, it just does not seem to work in IE if it's not HTML.