Abhishek Bhardwaj
Abhishek Bhardwaj

Reputation: 300

How to keep the next line \n from getting removed inside the email text?

All the \n are removed from the string when the text is put inside mail body .

 var valuess = Object.entries(feedBackText);

 valuess.forEach(function (key) {
    responseText = responseText.concat(' ' + key[0] + ':' + key[1] + '\n');
 });


 var parsedString = responseText.toString();
 window.location = "mailto:[email protected]"+"?subject="+subjectmail+"&body=" + 
 parsedString;

Upvotes: 0

Views: 29

Answers (1)

Adam Chubbuck
Adam Chubbuck

Reputation: 1670

The following demonstrates how you can solve this using the built-in encodeURIComponent function:

var parsedString = "text on the" + "\n" + "next line";

var link = "mailto:[email protected]" + "?subject=Example&body=" +
  encodeURIComponent(parsedString);

console.log(link);

Upvotes: 1

Related Questions