Is there a way to detect the start of a download in JavaScript?

In our current project we are providing a PDF download that can be customized by the user through an HTML form he submits. It takes several seconds to dynamically generate the PDF and I'd like to visualize this, e.g. by disabling the submit button until the download starts. Unfortunately, I couldn't find a way to detect when the download starts*. So I wouldn't know when to re-enable the submit button. I already tried to specify an IFrame as the target of my HTML form, hoping that the `onload` event would be triggered. It is not, however -- probably because the PDF is sent with a "`Content-disposition: attachment`" header and it is not actually loaded into the IFrame. The only solution I can think of right now involves generating the PDF to a temporary file on the server, which I would like to avoid. *)Let me clarify this: I wouldn't need to know if the download was finished or even if it was really started. I'd like to detect the point at which the browser will ask the user whether to open or to save the file. I guess this happens when the browser receives the HTTP header.
Do you want to know when the download starts or when it completes? Either way, I don't think that a temporary file will make a difference. On the client-side you can't tell if the file was sitting on the server or generated on the fly.

以上就是Is there a way to detect the start of a download in JavaScript?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏