Flask: Send_from_directory And Also Refresh The Page
I am using send_from_directory in flask which will allow a user to download a certain file. What I want to achieve is that the page refreshes after the file is downloaded, but I'm
Solution 1:
HTTP doesn't let you do what you want to do (200 + 300). You can do it at the client level however using _target
+ JavaScript (or just JavaScript).
<a href="/path/to/download/file" target="downloadIframe">Download file</a>
<iframe id="downloadIframe"></iframe>
Combined with some 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(); };
}
Post a Comment for "Flask: Send_from_directory And Also Refresh The Page"