Скачать CVS файл для Excel
function utf8_1251 (aa) {
var bb = [], c = 0;
for (var i = 0; i < aa.length; i++) {
c = aa.charCodeAt(i);
if (c > 127) {
if (c > 1024) {
if (c == 1025) {
c = 1016;
} else if (c == 1105) {
c = 1032;
} else if (c == 8470) {
c = 1033;
}
bb.push(c - 848);
}
} else {
bb.push(aa.charCodeAt(i));
}
}
return bb;
}
function popup(data) {
myarray=utf8_1251(data);
data1=new Uint8Array(myarray);
properties = {type: 'text/csv; charset=windows-1251'}; // Specify the file's mime-type.
try {
// Specify the filename using the File constructor, but ...
file = new File([data1], "file.txt", properties);
} catch (e) {
// ... fall back to the Blob constructor if that isn't supported.
file = new Blob([data1], properties);
}
url = URL.createObjectURL(file);
document.getElementById('link').href = url;
return true;
}