As Alastair pointed out, you will want to have a BOM at the beginning of the file if you want excel to behave correctly. But I believe it should be specified differently. Here is a complete working example of how to download (already encoded) a csv file that was built in the browser:
// not needed with firefox, chrome, ie11:
// window.URL = window.URL || window.webkitURL;
var data = "a,column b,c\nНикола Тесла,234,365";
// add UTF-8 BOM to beginning so excel doesn't get confused.
// *THIS IS THE KEY*
var BOM = String.fromCharCode(0xFEFF);
data = BOM + data;
var btn = document.createElement("button");
btn.appendChild(document.createTextNode("Click Me!"));
btn.onclick = function() {
var blob = new Blob([data], {type: "text/csv;charset=UTF-8"});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
// ie
var success = window.navigator.msSaveOrOpenBlob(blob, "Name of File.csv");
if (!success) {
alert("Failed");
}
} else {
// not ie
var a = document.createElement("a");
a.href = window.URL.createObjectURL(blob);
a.download = "Name of File.csv";
document.body.appendChild(a);
a.click();
// is there a problem with removing this from the DOM already?
a.parentNode.removeChild(a);
}
};
document.body.appendChild(btn);
The above works in current Firefox, Chrome, and IE11 -- if you open with excel, you will see Nicola Tesla's name in Serbian Cyrillic.