locked
Detecting when there is a response on an iframe? RRS feed

  • Question

  • 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#:

            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.

    Tuesday, July 20, 2010 3:49 PM

All replies

  • So for IE:

    ifrm.contentDocument.onreadystatechange = function() {
      if (/interactive|complete/i.test(this.readyState)) {
        // do something
      }
    }
    
    Trying to figure out FireFox now...

    Tuesday, July 20, 2010 5:28 PM