beforeunload 事件和 Content-Disposition=attachment

Efe*_*bel 5 javascript dom-events

我最近在我的代码中添加了这样的内容:

$(window).on('beforeunload', function () {
    $('.whirly-loader').show(); //SPINER
})
Run Code Online (Sandbox Code Playgroud)

因此,每当用户转到我的网络的另一侧时,旋转器就会出现。大多数时候它都有效。但是,在应用程序的某些部分,客户端开始转向另一侧,并且服务器使用以下标头进行响应:

Cache-Control
    max-age=0, must-revalidate, private
Connection
    Keep-Alive
Content-Disposition
    attachment;filename=suministro.csv
Content-Type
    text/csv; charset=utf-8
[...]
Run Code Online (Sandbox Code Playgroud)

这可以防止重新加载页面并仅显示要求下载或打开文档的窗口。我的问题是即使页面停止加载,微调器仍然显示

即使页面由于标题而没有重新加载,哪个事件应该隐藏我的微调器?

小智 0

您可以为下载链接添加属性目标。

例子:

<body onbeforeunload="document.body.style.backgroundColor = 'red';">
    <a href="output.zip" target="_blank">Download</a>
</body>
Run Code Online (Sandbox Code Playgroud)

属性target="_blank"将导致 onbeforeload 事件不会触发。