views:

22

answers:

1

I have created an AJAX style file download (using an iframe) and all works well... however, I need to detect when the iframe has received a response... see below:

Javascript:

function download() {
  var ifrm = $('#iframedownload')[0];
  ifrm.src = '/downloadfile.aspx?fileid=whatever';
  ifrm.onreadystatechange = function () { // Checking
    if (this.readyState == 'complete')
      alert("I would really like this piece to work!");
  };
}

C# for downloadfile.aspx:

Response.AddHeader("content-disposition", "attachment; filename=\"" + zipFileName + "\"");
Response.AddHeader("Content-Length", respBytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(respBytes); 
Response.End();

Thanks.

A: 

Handle the <iframe>'s onload and readystatechanged events.

SLaks
ifrm.contentDocument.onreadystatechange works for IE but not FireFox... only works when the container page first renders...
alex.davis.dev
Read this page: http://www.atalasoft.com/cs/blogs/jake/archive/2009/06/18/events-to-expect-when-dynamically-loading-iframes-in-javascript.aspx
SLaks