Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda