Javascript/jQuery: File download ready event
browser, javascript, jquery, php
Solution
I did it following this example: http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
For PHP, notice that this is how you send the cookie:
header('Content-type: application/octet-stream');
header('Set-Cookie: fileDownload=1; path=/');
header('Content-Disposition: attachment; filename='.$filename);
Path above is really important. Then JS also needs the path to remove the cookie, like this:
$.removeCookie('fileDownload', { path: '/' })
Problem
Is there any way to know that the browser event regarding file ready to download has fired? I have a script that generates a file, and while that is happening I show a laoding gif. Once this message appears: https://i.stack.imgur.com/CmZHE.png (file ready for download, script finished) I would like to stop the gif. Is it possible to know this with JS? Using ajax is an option but would take longer since it would require multiple modifications on the system. Thanks!