2

I had a project which is export a csv file and update the download time in admin page and it's worked normally when the browser Ask where to save each file before downloading is disabled. But just for example if the administrator accidentally turn it on then it will create a bug.

The bug : If he/she pressed cancel then my ajax code will still return success call and the download time will be updated despite no files are downloaded Bug Occur when press this button

I don't know if there is a way to check if the Ask where to save each file before downloading is activated or not ?

I'm using Laravel 8 btw , and here is my JS code : enter image description here

Harron
  • 21
  • 2
  • please paste your controller code of download file – user1994 Jan 20 '21 at 04:29
  • this hack should work for you [Detect when browser has received the file](https://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download) – Sumit Wadhwa Jan 20 '21 at 04:42
  • @user1994 No need friend because the problem is not about I can't download file. It's about how can I check if the person browser has the 'Ask where to save each file before downloading' is turn on or not :))) – Harron Jan 20 '21 at 04:54
  • @s.wadhwa it's look promising :))) thank you ! I will give it a try – Harron Jan 20 '21 at 04:55

1 Answers1

1

This is possible through browser-native FS (https://developer.mozilla.org/en-US/docs/Web/API/FileSystem)

(Works with Chrome and maybe Firefox)

So first you'd do your ajax call to get the CSV file into JavaScript, and then use the BNFS. BNFS generates a user abort exception if the user clicks cancel, so then maybe you'd need to send a message back to the server saying that the download was aborted

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80