[Javascript] cr/lf problem in calling a mail window

Peter Brunone peter at brunone.com
Thu Apr 11 10:29:51 CDT 2002

cr/lf problem in calling a mail windowMathieu,

    You are in effect sending this information through the URL, so you need
to encode it.  Otherwise the slashes can be taken as directory markings or
escape characters... either way, you can't transfer a crlf as such through
the querystring.  Some server-side engines have a way around this; for
example, ASP has a function called Server.URLEncode() that can be used to
encode all such troublesome characters.
    The encoded value of cr/lf is %0A%0D; unfortunately, this throws a
javascript "unterminated string constant" error, which does not happen with
%20 (the encoded value for space).  After some trial and error, I found that
you have to escape the *letter* in this encoded value.  Don't ask me why;
perhaps someone with a better Jscript/C background can say.
    Anyway, the end result is that you should code like this example, which
works (watch for line wrapping):

HREF="javascript:window.location.href='mailto:peter at brunone.com?Subject=My%2
0Mail&Body=This%20is%20separated%0\A%0\Dfrom%20this';">Javascript Mail</A>

    Let me know how this works out for you.


  -----Original Message-----
  From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
Behalf Of FERON Matthieu
  Sent: Thursday, April 11, 2002 3:57 AM
  To: Javascript (E-mail)
  Subject: [Javascript] cr/lf problem in calling a mail window

  I use this code to build a mail
    window.location = "mailto:mymail at myserver.ext?Subject=Contribution HTM :
&Body=Titre:\nDescription:\nInsère ici un fichier zip contenant les pages et
images à relier\nDès que les pages seront intégrées dans le site, tu
recevras une confirmation par mail.";

  it works well and include my text in the right place but the '\n' doesn't
seem to work to include cr/lf.
  if anyone has an idea.
  Matthieu Féron
  mferon at adeuza.fr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20020411/a06133b7/attachment.htm>

More information about the Javascript mailing list