write NLCR to txt output

T

Tom de Neef

I try to construct a string for output in the body of an email. My problem
is to get new line/carriage return characters inserted.

On reading a txt file I can split lines successfully with split(/[\r\n]/)
(thanks to Thomas Lahn and Evertjan) or
split(String.fromCharCode(13)+String.fromCharCode(10)) (which is the
traditional #13#10 found in txt files).
But I fail in the reverse process. Neither

var s = "this \r\nor that"
nor
var s = "this '+String.fromCharCode(13)+String.fromCharCode(10)+'or that'

produces a new line during output to a mail body in
location="mailto:[email protected]?subject=This or that&body="+s
(Both work fine in alert(s) )

So: how to force a new line in txt output ?
Thanks
Tom
 
G

GArlington

I try to construct a string for output in the body of an email. My problem
is to get new line/carriage return characters inserted.

On reading a txt file I can split lines successfully with split(/[\r\n]/)
(thanks to Thomas Lahn and Evertjan) or
split(String.fromCharCode(13)+String.fromCharCode(10)) (which is the
traditional #13#10 found in txt files).
But I fail in the reverse process. Neither

var s = "this \r\nor that"
nor
var s = "this '+String.fromCharCode(13)+String.fromCharCode(10)+'or that'

produces a new line during output to a mail body in
location="mailto:[email protected]?subject=This or that&body="+s
(Both work fine in alert(s) )

So: how to force a new line in txt output ?
Thanks
Tom

It took me few attempts to remember how I used to do that, try this:
<script type="text/javascript">
var mailBody = "blah" + '\r\n' + "blah" + '\r\n' + "blah";
var newLocation = "mailto:[email protected]?subject=This subject&body="
+ escape(mailBody);
alert(newLocation);
location = newLocation;
</script>
 
T

Tom de Neef

I try to construct a string for output in the body of an email. My
problem
is to get new line/carriage return characters inserted.

On reading a txt file I can split lines successfully with split(/[\r\n]/)
(thanks to Thomas Lahn and Evertjan) or
split(String.fromCharCode(13)+String.fromCharCode(10)) (which is the
traditional #13#10 found in txt files).
But I fail in the reverse process. Neither

var s = "this \r\nor that"
nor
var s = "this '+String.fromCharCode(13)+String.fromCharCode(10)+'or that'

produces a new line during output to a mail body in
location="mailto:[email protected]?subject=This or that&body="+s
(Both work fine in alert(s) )

So: how to force a new line in txt output ?
Thanks
Tom

It took me few attempts to remember how I used to do that, try this:
<script type="text/javascript">
var mailBody = "blah" + '\r\n' + "blah" + '\r\n' + "blah";
var newLocation = "mailto:[email protected]?subject=This subject&body="
+ escape(mailBody);
alert(newLocation);
location = newLocation;
</script>

Ah, escape(), that does it. Thank you.
Tom
 
T

Thomas 'PointedEars' Lahn

Tom said:
in respons to:

Ah, escape(), that does it. Thank you.

Nevertheless, it is likely that the `mailto:' URI is going to fail
miserably, given the apparently predominant amount of Web mail accounts,
and the existence of Internet cafés. You are much better off using a
server-side formmailer instead noawadys, also regarding e-mail spam.

BTW, it's called CRLF (Carriage Return, Line Feed: \r [0x0D] followed by \n
[0x0A]).


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top