'Encoding issue when saving files with javascript?
i've been trying all day to setup a function that creates a file from plaintext or a stream in a razor page. i create csv plaintext in a backend and send it to a frontend where i can save it to a file.
most of the things i have tried have worked perfectly so far, i can save what i get from my backend. but when i look at the file, the character 'ø' has been replaced with "ø". i have tried specifying utf-8 format and encoded it as html or base64 and plaintext and nothing seems to work.
function saveFile(name, type, data) {
var a = $("<a style='display: none;'/>");
var url = window.URL.createObjectURL(new Blob([data], { type: type }));
a.attr("href", url);
a.attr("download", name);
$("body").append(a);
a[0].click();
window.URL.revokeObjectURL(url);
a.remove();
}
is the way my code currently looks. any ideas? thank you
Solution 1:[1]
It actually worked perfectly, I later realized excel was trying to read it with american text which doesn't contain æ ø å. opening it with notepad showed what i was expecting
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marius Rogne |