Is there any way to detect if a user has selected ok or cancel to download a file in JavaScript? For instance if I have a link that points to a file and a user clicks on it <a href="file.xls">download</a> that will automatically start the download of the file, but how do I know if the user has been prompted to do download or not?
Is there any way to detect if a user has selected ok or cancel
Share
If they’ve clicked on it you can be pretty sure they’ll be prompted to download it. To find out if they’ve downloaded it though, you’d need to implement that on the backend. There is no way the webpage itself will be able to know.
On the backend you’d have to monitor the communication with the client via the web server and see how much data has been transferred to the client and compare that with the total size of the file.
You could then make this data available on the server and using some sort of XMLHttpRequest or websocket, the page could update with a progress bar if that’s what you’re looking for.