html - Javascript adding linebreak in mailto body -
i'm setting body of email using values form
firstname = bob lastname = dole ebody = 'first name: ' + firstname + '\r\n' + 'last name: ' + lastname window.location.href = 'mailto:myemail@mycompany.com?subject=test email&body=' + ebody;
if "alert(ebody);" linebreak between firstname & lastname, when opens outlook, entire ebody string appears without linebreak in email body.
i've tried \n also. there can give line break?
thanks in advance
rfc 2368 says mailto body content must url-encoded, using %-escaped form characters encoded in url. characters includes spaces , (as called out explicitly in section 5 of 2368) cr , lf.
you writing
ebody = 'first%20name:%20' + firstname + '%0d%0a' + 'last%20name:%20' + lastname;
but it's easier , better have javascript escaping you, this:
ebody = 'first name: ' + firstname + '\r\n' + 'last name: ' + lastname; ebody = encodeuricomponent(ebody);
not save having identify , hex values of characters need encoded in fixed text, encode goofy characters in firstname
, lastname
variables.
Comments
Post a Comment