system — 2000-11-22T06:30:39-05:00 — #1
I'm looking for some java script which will help me perform the the following function:-
I want to have a 'mail this page to a friend button on each of my pages which automatically opens up a new e-mail in the users microsoft outlook and insets the page url in the body of the e-mail (using the mailto: function).
I know you would insert a link like this:
<a href="mailto:?subject=send a page url&body=URL of current page">Send this page
to a friend</a>
BUT: Is there any way that I can do this (possibly using a JS function) that would automatically enter the URL of the 'current page' into body= , rather that hand coding it for every page?
I've got over 600 page so handcoding would be a real chore!
creole — 2000-11-22T14:10:11-05:00 — #2
Chilli...don't know if this would work...
<a href="mailto:?subject=send a page url&body=$PHP_SELF">Send this page
to a friend</a>
system — 2000-11-22T15:11:38-05:00 — #3
I've just tried it as you said and it just inserts
$PHP_SELF into the body.
Any reason for this not working? I host with hostrocket who have PHP on the servers - so that should be ok. Do I need to save the file with a php extension?
Sorry I'm not at all clued up on scripting.
system — 2000-11-22T15:18:53-05:00 — #4
just tried it by changing the file extensions to .php & .php3 an that didn't work either.
twtcommish — 2000-11-22T15:46:07-05:00 — #5
The $PHP_SELF variable will only work if inside php code, and inside an echo statement. Like this:
echo("<a href=\"mailto:?subject=send a page url&body=$PHP_SELF"\>Send this page to a friend</a>");
var ref = document.referrer;
document.write("<a href=\"mailto:?subject=send a page url&body=" + ref + \">Send this page to a friend</a>");
See if that works.
twtcommish — 2000-11-22T15:50:51-05:00 — #6
Hmmm, that doesn't seem to work, but I'm not sure why. Anyone have any ideas? I'm stumped.
system — 2000-11-22T17:29:53-05:00 — #7
I don't know if this could help you but I got this short reply when I posted on Webhostingtalk.
document.write('<a href= etc, etc, etc '+top.window.location
My JS is limited to say the least (deamweaver set functions) so I didn't know exactly how to implement this with the proper tags etc.
cyberbrain — 2000-11-22T18:52:28-05:00 — #8
This seem to be working for me...however i'm not sure that works with every browser/platform/emailclient...
send_it = "mailto:?subject= bla bla bla bla ";
send_it += "&body= check this web page bla bla bla "+ document.location;
document.location = send_it;
And here the call to the function:
twtcommish — 2000-11-22T18:57:03-05:00 — #9
If you're worried about compatibility, just use PHP in the echo command I mentioned earlier - compatible with anything that even resembles a browser.
etlux — 2000-11-23T02:41:24-05:00 — #10
This will open the standard email client; grab the title and url of the page and place them in the email body; insert the e-mail address entered in the <form> text box in the email To: box; and place a message in the email Subject line.
<title>This is a page</title>
<body bgcolor="#ffffff" text="#000000" id=all>
E-MAIL THIS LINK
Enter recipient's e-mail:
<input type="text" name="address" size="25">
<input type="button" value="Send this URL" onClick="mailThisUrl();">
u = window.location;
m = "I thought this might interest you...";
window.location = "mailto:"+document.Mailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
Take care to get the entire window.location = "mailto... etc. in the function all on one line.
Edited by etLux on 11-23-2000 at 03:43 AM