简体   繁体   中英

How to know when a download has finished?

Is there a way to tell if when a download has finished? That is, we allow users to download a report in PDF format. It takes about 3 - 5 seconds to start downloading and in this time, from click to end of download, show a wait state icon so that the user doesn't click multiple times.

Thanks! Eric

Ok so this is what we did.

When a user clicks on the link to download the PDF, we show a wait state icon and make an async request to the app server to start the PDF build. When the process is done it returns the URL of the PDF. After this, we remove the wait state image and set location.href = url. I think this is the best solution.

Thanks all for the ideas/suggestions/code!

您可以在单击后禁用该链接5秒钟,并显示隐藏的等待图标。

This is non-trivial. If you're using a script to send the PDF file, you could set a flag somewhere to indicate the script has completed sending the data. But this just means the script is done. It doesn't mean the bytes have been sent anywyhere. They could be stuck in the webserver's outbound queue waiting for a free slot to actually get sent out on the wire.

Best solution I've seen for this is to pop up a new window to start the download, and put the usual "please wait, I'm thinking..." animation/text in it. To keep the user from clicking the original donwload button multiple times (and popping up multiple download windows), you could put in a bit of javascript to disable the button for a short period.

Can you use javascript to disable the button once it has been clicked? ( http://www.codetoad.com/javascript/enable_disable_form_element.asp )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM