4

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
  • 12,698
  • 5
  • 49
  • 84
Eric Chan
  • 1,122
  • 3
  • 14
  • 29

2 Answers2

1

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
  • 607
  • 2
  • 9
  • 15
-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'});