Escaping a CrLf in JavaScript

G

George Durzi

I'm trying to pop up a mailto: window using server side script, here's how
I'm doing this.

string sBody = string.Concat("Test", @"\", Environment.NewLine, "Test",
@"\", Environment.Newline);
string sSubject = "Test Email";
string sScript = string.Concat(@"window.open('mailto:?subject=", sSubject,
"&body=", sBody, "')");

StringBuilder sbEMNote = new StringBuilder();
sbEMNote.AppendFormat("{0}{1}{2}", @"<script language=javascript>", sScript,
@"</script>");

if (!Page.IsStartupScriptRegistered("EmailIndividualNote"))
Page.RegisterStartupScript("EmailIndividualNote", sbEMNote.ToString());


If I step through my code, sBody looks like this:
Test\\\r\nTest\\\r\n

I had to put the @"\" before the Environment.Newline otherwise JavaScript
gives me an "unterminated string constant" error.

Anyhow, everything works, except the Body of my email contains TestTest. The
crlf was ignored. Any idea why this is happening?
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top