Forum Moderators: open

Message Too Old, No Replies

Tell a friend script truncates URL after & character

         

penstaar

6:27 pm on Feb 26, 2007 (gmt 0)

10+ Year Member



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>

scriptmasterdel

10:07 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



Can you not use unescape to pass the strings?

e.g.

window.location = 'mailto:' + field.value + '?subject=' + unescape( email_subject ) + '&body=' + unescape( email_body + page_url +'\n\n');

Just a thought.

Del

penstaar

5:43 pm on Feb 28, 2007 (gmt 0)

10+ Year Member



But unescape just takes me back to where I started...

Fotiman

6:29 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are escaping it twice. Remove this line:

page_url = escape(page_url);

Since you are escaping it later on:

window.location = 'mailto:' + field.value + '?subject=' +
escape( email_subject ) + '&body=' +
escape( email_body + page_url +'\n\n');

[edited by: Fotiman at 6:33 pm (utc) on Feb. 28, 2007]