title: How to get iframe response http codes onload?
body: <p>I'm working on an ajax-enabled page and I need to download files without refreshing the page. In order to do this, I added a hidden iframe on the page.</p>
  
  <pre><code>&lt;iframe id="iframeDownload" style="display:none"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>When I need to download a file, I use a script like this:</p>
  
  <pre><code>$("#iframeDownload").attr("src","url to server");
  </code></pre>
  
  <p>On server side, I need to implement some logic and it may return some different http status codes to indicate problems on server side. If the file is downloaded successfully, then it's fine. But in case there is a problem on server side, I need to catch these http codes.</p>
  
  <pre><code>$("#iframeDownload").load(function(e){
      // get http status code and act accordingly but I cannot get it
  });
  </code></pre>
  
  <p>Thanks for any reply.</p>
  
  <p><strong>Update:</strong>
  In my opinion, when we download via iframe, the browser will handle sending requests and receiving responses and only pass the response body to the iframe. Therefore, javascript cannot read response header. This case is similar to loading a page. Please correct me if I'm wrong.</p>