Detect when browser receives file download

前端 未结 22 1686
陌清茗
陌清茗 2020-11-21 04:55

I have a page that allows the user to download a dynamically-generated file. It takes a long time to generate, so I\'d like to show a \"waiting\" indicator. The problem is,

22条回答
  •  既然无缘
    2020-11-21 05:28

    When the user triggers the generation of the file, you could simply assign a unique ID to that "download", and send the user to a page which refreshes (or checks with AJAX) every few seconds. Once the file is finished, save it under that same unique ID and...

    • If the file is ready, do the download.
    • If the file is not ready, show the progress.

    Then you can skip the whole iframe/waiting/browserwindow mess, yet have a really elegant solution.

提交回复
热议问题