I am trying to download a file and then reload the page.
The issue is that this code works only when the file download is completed within a second.
If the file is any bigger the first request to download the file seems to be blocked by the second request.
javascript:
//downloads the file
function updateAndDownload() {
var link = document.createElement('a');
link.href = "updateAndDownloadFile.rails?id=$ID";
document.body.appendChild(link);
link.click();
PageReload();
}
//wait for a second and refresh the page
function PageReload() {
setTimeout(function() {
refreshPage();
}, 1000);
}
function refreshPage() {
// Close dialog.
Control.Modal.close();
// Reload.
window.location.href = "index.rails?id=" + ID
}
I expect the file to be downloaded and the page to be refreshed maybe back to back or at the same time