News & Updates
Clients & Partners
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;
}
Care to comment?

Creative Portfolio
