7

I am using Javascript to create a CSV file for user to download.

Until May 22nd, Chrome still downloaded the file with the name I specified. However, today I found that the files downloaded are named "download" and do not have the extension .csv.

This problem does not exist in Firefox!

Here is a fiddle with sample Javascript:

var A = [['n','sqrt(n)']];  // initialize array of rows with header row as 1st item
for(var j=1;j<10;++j){ A.push([j, Math.sqrt(j)]) }
var csvRows = [];
for(var i=0,l=A.length; i<l; ++i){
    csvRows.push(A[i].join(','));   // unquoted CSV row
}
var csvString = csvRows.join("\n");

var a = document.createElement('a');
a.href     = 'data:text/csv;charset=utf-8;base64,' + window.btoa(csvString);
a.target   = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();
1
  • That's weird... Last time I tried this it worked just fine in Chrome too. I'll have a look at why this is happening. Commented May 25, 2014 at 21:23

1 Answer 1

5

Nice work! This is a regression.

I just created another fiddle, and filed a Chrome bug.

If you're interested, star it in the bug tracker.

<a href="/" download="my-downloaded-file.html" target="_blank">Click here</a>

EDIT: It look like it depends on the URL. Absolute URLs work, as well as objects URLs (according to https://code.google.com/p/chromium/issues/detail?id=376197).

Sign up to request clarification or add additional context in comments.

7 Comments

The error report is not completely correct though. only data-URIs don't work anymore.
I'm sorry, I take that back (also removed Google forums post). I'm sure I must have been looking at the wrong thing or something, but I thought it worked. I have no idea if I was just derping there (probably) or if it was something else, but you're right.
so...this is a bug in one of the chromium update right?
fwiw @PaulDraper jsfiddle working ok at chromium 31. at Joeytje50 Both links at jsfiddle work ok at chromium 31. jsfiddle at original post work ok, too. Is issue with chrome/chromium 35+ ? Thanks
@guest271314, yes hence "This is a regression".
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.