Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!