Line break in the mailto onclick

12,743

You need to use the ASCII values for line feed/carriage return:

%0A = \n

%0D = \r

%0D%0A = \r\n

Works like a charm.

<a href="mailto:[email protected]?subject=My subject&body=Hello %0D%0A World">Link</a> 

(Spaces added around %0D%0A for clarity. In reality, this could add unwanted white space.)

Share:
12,743
malaki1974
Author by

malaki1974

Insanity one byte at a time.

Updated on June 12, 2022

Comments

  • malaki1974
    malaki1974 almost 2 years

    The code below works great except the email has all the text on one line like this: Height: 60 | Diagonal: 123 | Width: 107 | Total SF: 13.92 | Cost Per SF: 450 | Total Cost: $6,264.00

    I would like to break after each so it looks like this:

    Height: 60
    Diagonal: 123
    Width: 107
    Total SF: 13.92
    Cost Per SF: 450
    Total Cost: $6,264.00

    I tried \n \r \n\r etc but none of them work. Any ideas?

    <a class="emailText" href="mailto:?subject=Screen Dimensions" onclick="this.href='mailto:?subject=Screen Dimensions&body='+'Height: '+document.forms.myform.high.value+' | '+'Diagonal: '+document.forms.myform.diagonal.value+' | '+'Width: '+document.forms.myform.wide.value+' | '+'Total SF: '+document.forms.myform.sf.value+' | '+'Cost Per SF: '+document.forms.myform.csf.value+' | '+'Total Cost: '+document.forms.myform.tc.value">Email</a>
    
  • bumerang
    bumerang about 11 years
    Your great man I would spend all day looking for it. I love this site.
  • Ben Sewards
    Ben Sewards over 10 years
    Has anyone else noticed that doing so strips off the email signature in Outlook?
  • Markus Bucher
    Markus Bucher almost 9 years
    You won't be able to use HTML inside mailto-Links.