SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just tried it by changing the file extensions to .php & .php3 an that didn't work either.


  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>


    See if that works.

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, that doesn't seem to work, but I'm not sure why. Anyone have any ideas? I'm stumped.

  7. #7
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.




  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  9. #9
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're worried about compatibility, just use PHP in the echo command I mentioned earlier - compatible with anything that even resembles a browser.

  10. #10
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


    Edited by etLux on 11-23-2000 at 03:43 AM


Bookmarks

Posting Permissions

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