1

I have a button that lets users download a file. The file is returned from the server in the Response (binaries set as attachment), and I am letting the browser handle the file download from there on out.

Im doing the following on button click:

var fileUrl = 'mysite.com?id=12345';
document.location.href = fileUrl;

This will load the file, however, it can take a couple of seconds. I would like to show a preloader but then ofcourse I have to know when the file has been downloaded completed. Since I'm staying on the same page, is there a method or callback that tells if the 'new' location is loaded and thus I can hide the preloader?

Thanks!

NeedACar
  • 921
  • 2
  • 8
  • 27
  • possible duplicate of [Detect when browser receives file download](http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download) – Chad Killingsworth Feb 24 '15 at 21:41

1 Answers1

0

Assuming you can download the file twice, you could load the file in a hidden iframe and detect when the iframe is done loading. Then, the file is already cached and should download quickly.

firefoxuser_1
  • 1,793
  • 13
  • 22
  • I didnt 'really' use this 2-downloads route, however, I did go the iFrame route, including a cookie to set the status, based on the mentioned duplicate question. – NeedACar Feb 25 '15 at 14:23