How can I pass the URL of the current page to mailto?
May 3, 2010 2:15 PM   Subscribe

Can I construct a mailto link that puts the URL of the current page in the message body?

So I want to put a little bit of code at the bottom of each article I write, "If you enjoyed this article, please share it with a friend," with a mailto link.

What I would really love is to be able to construct a piece of code that I can plop down on each and every page, and it pulls the URL of the page it is currently on and drops that in the body of the email, drops some explanatory text in the subject line (that part I can handle).

Looking at the documentation for the mailto process, it doesn't look like this is possible ... is it? Or is there some better way to accomplish this easily?

I must stress that it has to be a zero-IT solution - I cannot install plugins or scripts of any sort, and need to figure out a way that strictly takes place in the editorial/post component of my sites. If I have to, I will build the links manually, but would really love it if there was some ultra-slick way to do this.
posted by jbickers to Computers & Internet (5 answers total) 5 users marked this as a favorite
 
The email is the simple part. You pass subject and body parameters in the link. Tutorial that includes a bit on codes for special characters like spaces and how to add text to the mail body.

Don't know how you'd make portable code that can grab the current URL without scripting though.
posted by anti social order at 2:30 PM on May 3, 2010


Without scripting capabilities you will have to manually create the links...

<a href="mailto:?subject=this is a subject&body=this text gets added to the body">If you enjoyed this article, please share it with a friend</a>
posted by axismundi at 2:41 PM on May 3, 2010


Best answer: <a href="mailto:?subject=this is a subject&body=[sub]" onclick="this.href = this.href.replace('[sub]',window.location)">email</a> should work.
posted by nihlton at 3:06 PM on May 3, 2010 [2 favorites]


To be clear, what nihlton suggests is scripting, but it's not the sort of thing that requires any kind of installing.

And it does work with the minor caveat that it replaces the first instance of [sub] in your href attribute (everything contained by double quote marks immediately after "href="). So if for some reason you have "[sub]" in your subject, the url will go there and ignore a [sub] in your body.
posted by juv3nal at 4:36 PM on May 3, 2010


Response by poster: Brilliant ... yes, should have specified that I meant no scripts installed on the server. But this is exactly what I was looking for.

A million thanks!
posted by jbickers at 4:57 PM on May 3, 2010


« Older Extremely Loud and Illuminated by the History of...   |   Best way to ship a home server overseas Newer »
This thread is closed to new comments.