title: Load download in browser background, tell when finished
body: <p>I'm trying to get a file which takes a good few seconds to load in the background, so I can display a spinner at the same time. </p>
  
  <p>I'm currently trying with an iframe in the background, and this works but I'm not sure how I can be notified when it's finished loading (so I can remove the spinner). </p>
  
  <p>Any good ways of doing this? Any better solution than an iframe?</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function() {
          var link = $('.generate-pdf');
  
          link.click(function(e) {
              e.preventDefault();
              var spinner = $("&lt;img src='/assets/images/ajax-loader.gif' /&gt;");
              var iframe = $('&lt;iframe src="' + link.attr('href') + '" style="height:0;width:0;visibility;hidden;display:none;"&gt;&lt;/iframe&gt;');
              link.before(spinner);
              link.before(iframe);
  
          });
      })
  &lt;/script&gt;
  </code></pre>
  
  <p>According to <a href="http://www.atalasoft.com/cs/blogs/jake/archive/2009/06/18/events-to-expect-when-dynamically-loading-iframes-in-javascript.aspx" rel="nofollow">this site</a>, given that my <code>Content-disposition</code> is <code>attachment</code> I can't guarantee to receive any events. Can I poll any properties on the iframe to find out?</p>