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

115
Visualizações
Lost new-lines in JQuery text() in FireFox

I have a DIV at the page which I want user to be able to download as a text file (this is a license key). This DIV has \n symbols which is correctly displayed using white-space: pre;. I use the code bellow to create temporary <a> link with DIV content and download it. This works fine in Chrome, but FireFox loose the new-line symbols and I get single-lined text.

downloadLicenseBtn = $("#download_license");
downloadLicenseBtn.click(function(e){
    e.preventDefault();
    var $temp = $("<a>");
    $(body).append($temp);
    $temp.attr({
        download: 'license.txt',
        href: "data:text/html," + $('.edd_sl_license_key').text() 
        })[0].click()
    $temp.remove();
});

I tried to use JQuery html() function instead of text(), tried to set up data:text/plain;charset=utf-8. No luck. :(

JSFiddle here: https://jsfiddle.net/movs21/vy4ukdpr/

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Need to use encodeURIComponent( text ), also it's possible to replace \r\n with %0D%0A: replace('\n', '%0A', text).

Same question here: Javascript export text file not recognizing \r\n in firefox

about 4 years ago · Juan Pablo Isaza Relatório
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