Using hex code escape characters in tell a friend script

Discussion in 'JavaScript' started by kitkat, Feb 26, 2007.

  1. #1
    Hi there,

    I'm using the javascript tell a friend script below, and since my dynamic URL was being truncated because of the &, I use the javascript escape function to change all special characters to their hex code equivalents.

    Now my URL that I want to send to a friend appears in the email to them with all of the escape characters. Firstly, it will look weird to whoever I send it to, but also when I copy and paste the hex encoded URL into my browser, it doesn't work.

    Does anyone know why that is, or what I am doing wrong?


    <FORM name='email_friend_script'>
    <TABLE>
    <TR>
    <TD><INPUT type='text' name='address' size='25' maxsize='128'></TD>
    <TD><INPUT type='image' src='/images/temp/tell_a_friend.gif' onClick='jsMailThisUrl();'></TD>
    </TR>
    </TABLE>
    </FORM>

    <SCRIPT language='javascript'>
    <!--
    function jsMailThisUrl()
    {
    var email_subject = 'Check out this web page I found...';
    var email_body = 'Check out this great new feature story: ';
    //var page_url = window.self.location.href.split( '?' )[0];
    var page_url=window.location.href;
    //page_url = page_url + '';
    page_url = escape(page_url);
    var field = document.email_friend_script.address;
    window.location = 'mailto:' + field.value + '?subject=' +
    escape( email_subject ) + '&body=' +
    escape( email_body + page_url +'\n\n');
    }
    //-->
    </SCRIPT>
     
    kitkat, Feb 26, 2007 IP
  2. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #2
    The code is working when I tried it. Can you upload a demo page showing the exact error?
     
    Aragorn, Feb 27, 2007 IP
  3. kitkat

    kitkat Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I guess you could say the script works... I don't get an error, but the body of my email message looks like this:

    Check out this great new feature story: http%3A//www.somesite.com/subpage.asp%3FsectionID%3D752

    The above "URL" is not working in my browser.

    Let me know if you need anymore info and thank you for your response!
     
    kitkat, Feb 28, 2007 IP
  4. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I tested the script http://localhost/TestEmail.html?show=Test Me with IE, Firefox and Opera.
    With IE and Firefox I got "Check out this great new feature story: http://localhost/TestEmail.html?show=Test%20Me"
    With Opera the body was "Check out this great new feature story: http://localhost/TestEmail.html?show=Test%20Me%0A%0A"

    And the links did work in all three cases. Which is your mail client?
     
    Aragorn, Feb 28, 2007 IP
  5. kitkat

    kitkat Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mail client is Lotus Notes on OSX

    and I also tested on my other Mac, mail client Entourage on OSX... and it still comes out as http%3A//www.somesite.com/subpage.asp%3FsectionID%3D752

    :(
     
    kitkat, Feb 28, 2007 IP
  6. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #6
    I'm sorry, I can't be of any help then. I have never worked on OSX. :(

    Using the mail client for sending the mail seems very unprofessional. If you have server side scripting support, google for some similar scripts in PHP or ASP. That will be much more easier for users too.
     
    Aragorn, Feb 28, 2007 IP
  7. kitkat

    kitkat Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    *sigh* you are right... server side it is.

    thank you so much for your help. I marvel at how much time you must spend on here.
     
    kitkat, Feb 28, 2007 IP
  8. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #8
    I joined DP eight days back. I used to ask for help and used to study many free codes when I started programming. So I thought I should be giving something back to the webmaster community. Ofcourse, I am partcipating in the revenue sharing too :D. Since I joined DP, I spend atleast 8 hours a day browsing the forum.

    :)
     
    Aragorn, Feb 28, 2007 IP