I have a function to download files:
downloadFile(url, filename) {
var link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link = null;
},
This function work with .csv
and .xlsx
files. When a user click to a button .txt
file supposed to download too. If it is a txt file nothing happens.
I add this this two lines to code;
if(url.includes(".txt")){
link.target = '_blank';
}
It looks like this;
downloadFile(url, filename) {
var link = document.createElement('a');
link.href = url;
link.download = filename;
if(url.includes(".txt")){
link.target = '_blank';
}
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link = null;
},
When a user want to download the txt file it opens on a tab of browser and they need to right click and save the file over and over again.
For example this link; Example txt file
So how can I make the URL ending with .txt
extension downloadable?
This solution tried but it is not link, it just content. Not Work