Click to See Complete Forum and Search --> : send hyper link through email using js??


shanuragu
09-08-2003, 02:20 AM
Hi

On my new site I am planning to introduce an option to allow the user to recommend my web site to any of their frieds.
I am achieving this by providing a text box to enter one of their friends email address & click a button "send the link" which opens an email box with the respective email id, subject as " I thought this page might interest you..." & in the body section I want to send my web site link - when clicked should take them to my web site.

The whole process is achieved through js. Here is the code.

<SCRIPT LANGUAGE="JavaScript">
<!--- Begin
var good;
function checkEmailAddress(field) {
// the following expression must be all on one line...
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid e-mail address.');
field.focus();
field.select();
good = false;
}
}

u = "http://www.mywebsite.com";
m = "I thought this page might interest you...";
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.address);
if (good) {
// the following expression must be all on one line...
window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+u+" ";
}
}
// End -->
</script>


e-mail this <font face="verdana, arial, helvetica, courier, courier new" size="-2"><b>mywebpage.com</b></font> page link to a friend
<br>
by entering a recipient's e-mail address
<br>
<input type="text" name="address" size="25">
<br>
<input type="button" value="then send the link!" onClick="mailThisUrl();">

I am successfully displaying the email box, & the link at the body , but unable to click the link & display my web site??

What is wrong with this code??? please help.

:confused:

lillu
09-08-2003, 04:39 AM
Hi,

I looked at your code and think there's really just a bit of tidy-up what is needed so I will work on it later, time permitting.

Till then, I can give you this piece of code I use to accomplish the same idea but as you'll see it does not really work with the send button, as now the user has to click send twice. Once on the page and again in the mail.

<html>
<head>
<script language="javascript">
function mailThisUrl()
{
mail = "mailto:+document.address.value+?subject=This page might interest you";
mail += "&body=" + "http://www.geocities.com/lillamarta";
location.href = mail;
}
</script>
</head>
<body>

Recommend my page to a friend!
<br />
Recipient's e-mail address
<br />
<input type="text" name="address" size="25">
<input type="button" value="Send" onClick="mailThisUrl();">
</body>
</html>

Well, I may be wrong but I think the mailto: script will always open up the default mail system so if you want to send a message otherwise, you should make a form with a submit function.

HTH,

Lillu