是否可以在下载完成之前禁用按钮?

Is it possible to disable a Button until download is finished?

我正在尝试解决以下问题,但找不到合适的解决方案:

Disabling a button (with an underlying Download link) when the download starts (button has clicked once) and enable the button again when the download is completed?

我尝试 Google 它但甚至找不到有用的提示。这在一般情况下甚至可能吗?

3 个您可能想要查看的选项。

  1. 这个 link 作为开始的地方可能对您有用:

    http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/

    想法是使用 cookie 来定义何时下载文件。理论上,您可以编写 JavaScript 来检测 cookie,然后重新启用该按钮。在 JavaScript 中检测 cookie 的一个很好的概述可以在这里找到:What is the shortest function for reading a cookie by name in JavaScript?

  2. 另一个解决方案可能是看看这个问题: detecting when the "File download" popup is closed

    虽然这不是您要查找的内容 - Crescent Fresh 的答案可能会有所调整,以便在下载期间禁用您的按钮。

  3. 或者一个快速但不优雅的解决方案是禁用下载按钮 30 秒到 2 分钟之间的某个时间,以防止用户在文件下载时立即再次单击该按钮 - 这是最少的工作,但是它不考虑不同的下载速度等。

希望对您有所帮助!