0

I tried to toggle fade in and fade effect before and after the file was downloaded.

However, I was unable to check that the file download was completed or not before the fn_fadeOutWaiting() triggered.

I found the source here and here but it did not help for my case.

Here's my JS code is just like this:

fn_fadeInWaiting(); 
document.location = "/Employee/Data?Type=CSV";
fn_fadeOutWaiting();

If the downloaded file size (*.csv) is small, the fn_fadeInWaiting() and fn_fadeOut() triggered at right time. However, if downloaded file size (*.csv) is a bit larger, the fn_fadeOutWaiting() was triggered even if the file was not yet downloaded.

How can I trigger fn_fadeInWaiting() and fn_fadeOutWaiting() correctly for the downloaded file? Thanks.

Houy Narun
  • 1,557
  • 5
  • 37
  • 86
  • If the cookie approach isn't working I doubt there is any other approach that you can use – charlietfl Jan 23 '18 at 13:27
  • @charlietfl, thanks. I tried using `$.ajax()` `beforeSend()` and `success()` as well but not help solved. – Houy Narun Jan 23 '18 at 13:30
  • 1
    You can use an xhr request to download the file, check [this link](http://www.alexhadik.com/blog/2016/7/7/l8ztp8kr5lbctf5qns4l8t3646npqh) and then just check for the xhr response. – cнŝdk Jan 23 '18 at 13:33
  • @chŝdk, following the link above, it works fine, however I would like skip giving file name manually here `a.download = 'myFile.pdf';` because I already config to name file automatically by giving the current date and time as the file name. So, can I skip this step above? Thanks. – Houy Narun Jan 24 '18 at 02:00
  • @HouyNarun Yes of course, you can skip it, it's just used ofor the name of the download, you can set it tha way you want. – cнŝdk Jan 24 '18 at 13:47

0 Answers0