Check if the user accepted a file download in JavaScript
How do I开发者_如何学编程 check if the user accepted a file download in JavaScript. Example: If the site pops up a download link, and the web browser asks the user to download the file, how do I determine on that page if the user accepted the download or not?
JavaScript will not have access to that information. In general, JavaScript inside web browsers is limited to simply interact with the DOM.
You may be able to do something on the server-side that logs the start of the download stream, but as @Pointy and @Marcel noted in comments to another answer, this could be quite tricky. In such a case, you would then be able to ask the server for this information using AJAX, or long polling, etc, in near real-time.
You will have to do it indirectly by checking the web server log file via an AJAX call. This will require you to write some server side code (and you must have access to the log files).
There's a second way of doing it, and that's to stream the file through a server side program. That way you can set a flag when the file has started to stream and retrieve this flag via an AJAX call.
精彩评论