how to use javascript to download a file on Chrome without Chrome auto renaming file to "download"? [duplicate]
- by user3688566
This question already has an answer here:
Is there any way to specify a suggested filename when using data: URI?
11 answers
I use javascript to generate a file and download.
It seems that depending on the version of chrome, the download file names can be auto renamed to 'download'. is there a way to avoid it?
this is my code:
var link = document.createElement("a");
link.setAttribute("href", 'data:application/octet-stream,' + 'file content here');
link.setAttribute("download", 'file1.txt');
link.click();
This is not a duplicated question because i am using the latest chrome and the previously suggested hyperlink is exactly what i am using. I think chrome v34 works fine. but once my chrome autoupdated to v35, it went back to 'download' file name.