HTTP 不允许你做你想做的事(200 + 300)。您可以在客户端级别执行此操作,但使用_target
+ JavaScript(或仅 JavaScript)。
<a href="/path/to/download/file" target="downloadIframe">Download file</a>
<iframe id="downloadIframe"></iframe>
结合一些 JavaScript:
var slice = Array.prototype.slice;
var links = document.querySelectorAll("[target='downloadIframe']"),
iframe = document.getElementById("downloadIframe");
slice.call(links).forEach(function(link) {
link.addEventListener("click", reloadPageOnIframeLoad);
});
function reloadPageOnIframeLoad() {
// Reset this for each click on a download link
// rather than adding another event listener each time.
iframe.onload = function() { window.location.reload(); };
}