Detect "download event"

Asked

Viewed 641 times

0

I am providing a link to download XML files:

<a href="http://exemplo.com/link" download="">
   Baixe o XML do pedido
</a>

However, because it is a bit slow processing, due to the number of functions required, I would like to put a loading on the page so that the user does not have the feeling that nothing is happening. Because by clicking several times, the download is also done several times...

As far as I know, there is no event downlaod, but I need to exactly simulate this behavior, to be able to end the loading the moment the actual download is performed.

The loading I mean it would be simple, I do it myself, my question is to really simulate the event.

I would like to do in the simplest possible solution without using any plugin.

  • Kenny, I don’t understand well, if you are using a link, is it because the file is already ready correct? The only delay is in the download itself, depending on the file size and the user’s bandwidth. Where there is the slow processing you mentioned?

  • No, in vdd is just the opposite, the download is fast because the file is small, but the link is not to the direct file, but to another system on another server, that query in a sqlserver to fetch the file in a directory of another server and do the reading...I know it’s confusing, but what matters is that it really is the processing that takes a little while...

  • Kenny - the onclick doesn’t suit you? Another way would be to display a modal or a div superimposing your page with the warning that the download is starting and an option to close. This topic can also help you http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download

  • @leonardopessoa, trigger the event is simple, my problem is really in ending it automatically, had not thought of this solution with modal or some other warning, but if at first can treat automatically I prefer, but let’s see...

  • Particularly, I have never seen any site that has this functionality to detect the end of the download. It would be interesting to see working.

  • Yes, it could be as much when it’s over as when to start...

  • I don’t believe there is a download event, because the download is essentially another request. An alternative can be to use this link to generate the file via ajax. It is easy to use the loading. When the file is ready you get the response from ajax with the final URL to download and remove the file some time later, with a server routine.

  • It’s @Ricardomoraleida, I thought maybe there was some simple solution to do this simulation, but I think I’ll have to use something like...

  • @Kennyrafael thinks it’s simpler than looking for a cross-browser solution to an issue like this. Does not change anything for the user, it will be redirected to the download anyway, only ceases to be a direct link.

  • 1

    See if this helps: https://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download Using Cookies and GET/POST There’s also a plugin for this http://jqueryfiledownload.apphb.com/ although I’m not a big fan of using plugins for this sort of thing

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.