Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encoding specific part of URL

Status
Not open for further replies.

AdeleMB

Technical User
Mar 31, 2008
10
GB
I have an Email a Friend script for a website i work on but there are some problems with the encoding.

The Javascript opens the users email programme with a link to the refering page, but the page titles are in the URL's of each page and they are not being handled correctly i.e. when the email is recieved, the link goes to a 404 page as the punctuation in the title isnt converted correctly.

The problem is the punctuation in the page title inside the URL:
whatever/mim_forums_thread.htm?masterID=224&forumID=262&startPos=0&title=<b>Emails%20&%20Alerts!?!?!</b>

Is there a way that I can encode just this bit &title=<b>Emails%20&%20Alerts!?!?! without the rest of the URL being encoded? Some of the page titles have various bits of punctuation like ? . , ; " ... ??!! etc in them that need converting so they can be clicked from an email.

Any help is appreciated!!!
Adele x

Code:
<script type='text/javascript' language='JavaScript'>
function jsMailThisUrl()
{
var email_subject = 'Check out this topic';
var email_body = 'I found this topic and thought you might be interested: ';
//var page_url = window.self.location.href.split( '?' )[0];
var page_url=window.location.href;
//page_url = page_url + '';
var page_url = page_url.replace("-admin", "-user");
var page_url = page_url.replace("message-admin", "thread");
var page_url = page_url.replace("<b>", "");
var page_url = page_url.replace("</b>", "");
var page_url = page_url.replace(/ /g, "%20
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>
 
Hi,
sorry the missing characters are from my cutting and pasting - it is there in the original code and that bit worked fine.

All that is in the email is a line of text and the link, but the link contains the page title. Each time I tested it, it was not working as the page title part of the URL was not being turned into a link, it just appeared as plain text at the end of the URL. It must have been a caching problem or something as it is working today and I haven't changed anything yet!

Sorry for wasting your time and thanks for the reply anyway. :)
Adele
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top