There is actually a way that you can well guess that the browser is handling the file download. I asked the same question, and TJ Crowder had a great idea:
What are the methods to get around IE file upload security rules?
I am using this idea now and it works great. The trick is for the page to send the nonce parameter back with a random string of characters in it. The page then starts polling document.cookie every 100 milliseconds or so, checking to see if this string of characters is specified in the cookie.
The server, in turn, sets the selected cookie (it doesnโt really matter what it called) to the value sent by the form in the "nonce" parameter. Then it sends the file download, as usual.
When the HTTP response is returned to the browser, the cookie will be set. Javascript that polls the cookie value will see this, and it will know that the HTTP response is being processed. Now he will not know, of course, that the user did not hit Cancel when downloading the file.
If the server decides that the original request is erroneous (say, if the file upload includes a form, and the user provided an incorrect input or skipped a field), then it will not set a cookie and may simply respond with HTML for an error (or something else).
source share