开发者

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 downloa开发者_运维问答d, 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!


You could just disable the link for 5 seconds after it is clicked, and display a hidden wait icon.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜