5

I am trying hebrew csv file using javascript on Chrome extension.

But I got failed string.

enter image description here

Here is my code snippet.

var csv = "Phone\nאני אוהב אותך\n";
var file = new Blob([csv], {type: 'text/csv;utf-8'});
var url = URL.createObjectURL(file);
chrome.downloads.download({
    url: url,
    filename: name
}, function() {
    URL.revokeObjectURL(msg.url);
});
Balázs Édes
  • 13,452
  • 6
  • 54
  • 89
Eric Chan
  • 1,192
  • 4
  • 16
  • 30

2 Answers2

2

Try this:

var csv = String.fromCharCode(0xFEFF) + "Phone\nאני אוהב אותך\n";  // <--- here
var file = new Blob([csv], {type: 'text/csv;utf-8'});
var url = URL.createObjectURL(file);
chrome.downloads.download({
    url: url,
    filename: name
}, function() {
    URL.revokeObjectURL(msg.url);
});
Dror Bar
  • 686
  • 2
  • 10
  • 19
-1

It worked for me (in a HTML test page at least) to use utf-16 charset instead. It worked both for the entity codes and the actual hebrew characters to be printed as hebrew characters.

So, change

{type: 'text/csv;utf-8'});

to

{type: 'text/csv;utf-16'});