Recently a client specified that they'd like users to have the ability to email a pages from their website. I therefore went ahead and used the following Javascript function to create a HTML mailto:
function mailpage() {
mail_str = "mailto:?subject=I found a website that might interest you.";
mail_str += "&body=" + document.title "This might interest you too, " + location.href;
location.href = mail_str;
}
Unfortunately the body text of the email then displays on one line, which as one client remarked looked "...a little ungainly". Therefore we set to work to find a solution and discovered/remembered this - the Javascript escape()
method. Basically this accepts a string to be converted into url safe encoding. So all you have to do to see line breaks in your email is add "\n\n" and the rest is done for you. Finished code below:
function mailpage() {
mail_str = "mailto:?subject=I found a website that might interest you.";
mail_str += "&body=" + escape( document.title+"\n\nThis might interest you too, " + location.href );
location.href = mail_str;
}
THANK YOU!
Thanks A LOT !!!
After trying SEVERAL tips from multiple sources, FINALLY your example WORKED.
Great Job !
Add more lines
<script language="javascript">
function mailpage()
{
mail_str = "mailto:?subject=Webpage xxx " + document.title;
mail_str += "&body=I found...." + escape ("\n\n") + document.title;
mail_str += escape ("\n\n") + "You can find this information on the following location: " + escape ("\n\n") + location.href;
location.href = mail_str;
}
</script>
Ian
mailpage
Thanks, Jim, for saving me hours of experimentation!
Melissa
Only useful formatting tutorial on the internet
Thanks so much for this. After hours of searching, this was the only viable, straightforeward tutorial on how to insert hard returns I was able to find.
F
doesn't work anymore
Does not seem to work in new browsers.