How to know when an IE file download request appears?

Now I have a problem below:

I added a div to my page to prevent the user from clicking buttons, links or fields when the user clicks the DOWNLOAD button. Therefore, I need to delete this div when a request appears to download the IE file or when the user clicks โ€œsaveโ€, โ€œsave asโ€ or โ€œcancelโ€ on it.

How can I achieve this?

IE is considered only.

+1
source share
3 answers

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).

+5
source

No, browser file processing dialogs cannot be detected from javascript - this is by design. Even if you limit yourself to IE, this is not possible, and other browsers handle file downloads in completely different ways.

http://groups.google.co.uk/group/comp.lang.javascript/browse_thread/thread/9441cce4f8fdf20b/6f4fcc7796e03f1d

If you explain why you are trying to do this, there may be a different approach that suits you best.

+3
source

I do not think there is a callback for this; definitely not in all browsers.

In addition, not every browser gives a hint - and this depends on the browser configuration of a particular user; some may just start downloading in the background.

I suggest removing the DIV at some interval (which you will have to guess depending on the time it usually takes to show the boot window), although this is not a very clean workaround.

+1
source

Source: https://habr.com/ru/post/1311525/


All Articles