Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
Create and download an UTF8 plain text file from JS (browser)

I'm stucking on a problem that I cannot understand. I got an HTML page, declaring <meta charset="utf-8" />, attempting to create and download a text file, containing some UTF8 characters. The text is stored inside a JS variable and I'm trying to download the variable content as text file using the DataURI API. This is the code:

const myText = "àòùè";
const uriContent = "data:text/plain;charset=utf-8;base64," + btoa(myText);
const element = document.createElement('a');
element.setAttribute('href', uriContent);
element.setAttribute('download', "example_filename.log");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);

The resulting file is saved as ISO8859-15 and not in UTF-8 as declared in dataURI. It results in strange characters due to wrong encoding.

The encoding is checked using the file command under UNIX:

file example_filename.log
example_filename.log: ISO-8859 text
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda