Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What to change window.location to in Refer-a-Friend script

    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 :
    Code:
    "+window.location='http://www.yoursite.com'"
    but that doesn't work either. Can someone please help!

    This section in the Head tags :

    Code:
    <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)|(\.coop)|(\.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 :

    Code:
    <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>
    Last edited by grateful; 05-08-2009 at 01:02 AM.

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    I'm not sure if this is what you wanted, but it seems to be.

    Code:
    <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)|(\.coop)|(\.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>
    Last edited by TinyScript; 05-07-2009 at 01:51 AM.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I resolved the issue of getting the link in the email to be automatically hyperlinked, by adding the http://, thus :

    Code:
    u = "http://www.AccelerateInBusiness.com" //window.location;
    So now it's working perfectly. Thanks for the help.

    Margo :-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •