-1
I have an MVC project where there’s a button that does the download of files but when clicking the button opens a new guide in the browser and the files are automatically downloaded, as in the examples shown in this link:
https://www.w3schools.com/jsref/met_win_open.asp
My code works perfectly:
var url = "http://10.155.XXX.XXX/site_do_fornecedor/arquivo_para_download.aspx?id="
window.open(url + 10 + '10/12/2019', "_Blank", "width=200, height=100");
But I would like the screen to be displayed diálogo
where the user decides which directory to save the files in.
Example
When I click the button download the javascript code described above is executed and a Chrome window is opened:
How do I make this browser window not appear ?
I implemented the very interesting suggestion of Daniel Mendes:
function downloadMP3(_url, _strArrId, _data) {
fetch(_url + _strArrId + "&Date=09/12/2019")
.then(data => {
data.blob()
.then(blob => {
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = url;
link.click();
})
.catch(error => {
console.log(error);
});
})
.catch(error => {
console.log(error);
});
}
However the following error message was displayed:
From what I see the destination URL has to enable the CORS that’s right ?
By pure code I think it is not possible to display the save dialog as. The only way I see is if the user installs an extension in the browser that allows the code to call the dialog through the API downloads.
– Augusto Vasques