Javascript: unable to save file with encoding ANSI, charset ISO-8859-1

79 views Asked by At

I need to download from browser a file containing a string composed by

ASCII(161) + ASCII(162) + ASCII(163) + ASCII(164) + NewLine

and I need also to save it with charset 'windows-1252':

let data = "¡¢£¤\n"
var a = document.createElement('a')
var blob = new Blob([data], { 'type':'text/plain;charset=windows-1252' })
a.href = window.URL.createObjectURL(blob)
a.download = 'stefano.dat'
a.click()

https://jsfiddle.net/buonstefano/fmux8gdr/2/

The saved 'stefano.dat' file is download with charset UTF-8 and when I try to change encoding to ISO-8859-1, any character is prepended by  code: enter image description here

How can I get a file properly encoded in ISO-8859-1 and without  character? Can anyone help to understand what's wrong on that?

0

There are 0 answers