...

View Full Version : Resolved What to change window.location to in Refer-a-Friend script



grateful
05-07-2009, 12:11 AM
Hi, I'm very new to javascript, usually I just cut and paste. However, I need to change something in this code, and have looked through tutorials and forums with no luck. Would really appreciate some help.

The code is a "refer a friend" code, that at present places the URL of the current page into the email. I would like it to place the home/index page of the site into the email instead.

I tried changing window.location to parent.location, didn't work.

I tried :

"+window.location='http://www.yoursite.com'"

but that doesn't work either. Can someone please help!

This section in the Head tags :


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

var initialsubj="Have a look at this.."
var initialmsg="Hi:\n You may want to check out this site: "+window.location
var good;
function checkEmailAddress(field) {

var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.co op)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid address.');
field.focus();
field.select();
good = false;
}
}
u = window.location;
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.email);
if (good) {

//window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+document.title+" "+u;
window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+initialmsg
}
}
// End -->
</script>

The body section (in case this needs a change) is :


<form name="eMailer">
Tell a friend:
<input type="text" name="email" size="26" value=" Enter Address Here" onFocus="this.value=''" onMouseOver="window.status='Enter email address here and tell a friend about this site...'; return true" onMouseOut="window.status='';return true">
<br>
<input type="button" value="Send this URL" onMouseOver="window.status='Click to send an email (with this page address) to a friend! Enter email address above...'; return true" onMouseOut="window.status='';return true" onClick="mailThisUrl();">
</form>

TinyScript
05-07-2009, 12:46 AM
I'm not sure if this is what you wanted, but it seems to be.



<HTML>
<HEAD>


<script >

<!-- Begin

var initialsubj="Have a look at this.."
var initialmsg="Hi:\n You may want to check out this site: "
var good;
function checkEmailAddress(field) {

var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.co op)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid address.');
field.focus();
field.select();
good = false;
}
}
u = "www.putYourNewAddressHere"//window.location;
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.email);
if (good) {

//window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+document.title+" "+u;
window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+initialmsg+" "+u;
}
}
// End -->
</script>


</HEAD>

<BODY >
<form name="eMailer">
Tell a friend:
<input type="text" name="email" size="26" value=" Enter Address Here" onFocus="this.value=''" onMouseOver="window.status='Enter email address here and tell a friend about this site...'; return true" onMouseOut="window.status='';return true">
<br>
<input type="button" value="Send this URL" onMouseOver="window.status='Click to send an email (with this page address) to a friend! Enter email address above...'; return true" onMouseOut="window.status='';return true" onClick="mailThisUrl();">
</form>

</BODY>

</HTML>

grateful
05-07-2009, 02:16 AM
Hi TinyScript, many thanks for your very quick reply!

It works beautifully, exactly what I wanted - you are a genius!

Except for 1 tiny thing... if it's not too much trouble.
The URL in the email isn't hyperlinked, it's just text - is there a way to get it appear as a link?

Otherwise I'll use as it is.

I've tried other forums, but never got an answer, by the way. Really glad I found this one, I was tearing my hair out!

Margo

TinyScript
05-07-2009, 02:32 AM
u = <a href="www.putYourNewAddressHere">www.putYourNewAddressHere</a>//window.location;

try this. I don't use email from my machine at all, I just email from my online account, so I can't check the link for you. It looks like it works, but i don't know.

grateful
05-07-2009, 03:02 AM
I'm getting a Syntax error - Line 33, char 5, code 0.

So close!

When published and used, it does work, but URL still not hyperlinked.

Thanks for your patience.

grateful
05-07-2009, 11:59 PM
I resolved the issue of getting the link in the email to be automatically hyperlinked, by adding the http://, thus :


u = "http://www.AccelerateInBusiness.com" //window.location;

So now it's working perfectly. Thanks for the help.

Margo :-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum