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!
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?
The $PHP_SELF variable will only work if inside php code, and inside an echo statement. Like this:
<?php
echo(“<a href=\“mailto:?subject=send a page url&body=$PHP_SELF”\>Send this page to a friend</a>”);
?>
You can use JavaScript, however, to do this without having to rename your files .php/.php3:
<script language=“JavaScript”>
var ref = document.referrer;
document.write(“<a href=\“mailto:?subject=send a page url&body=” + ref + \”>Send this page to a friend</a>");
</script>
This seem to be working for me…however i’m not sure that works with every browser/platform/emailclient…
The script:
<script language=“javascript”>
function Send_this_page()
{
send_it = "mailto:?subject= bla bla bla bla ";
send_it += "&body= check this web page bla bla bla "+ document.location;
document.location = send_it;
}
</script>
And here the call to the function:
<a href = “javascript:Send_this_page()”>Send this page to a friend</a>
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.
<html>
<head>
<title>This is a page</title>
</head>
<body bgcolor=“#ffffff” text=“#000000” id=all>
<form name=“Mailer”>
E-MAIL THIS LINK
<br>
Enter recipient’s e-mail:
<br>
<input type=“text” name=“address” size=“25”>
<br>
<input type=“button” value=“Send this URL” onClick=“mailThisUrl();”>
</form>
<script>
u = window.location;
m = “I thought this might interest you…”;
function mailThisUrl(){
window.location = “mailto:”+document.Mailer.address.value+“?subject=”+m+“&body=”+document.title+" "+u;
}
</script>
</body>
</html>
Take care to get the entire window.location = "mailto… etc. in the function all on one line.