I have a bit of JavaScript for a Tell a Friend link. The person enters an email into a box clicks submit and their email programme opens a new mail with the URL from the referring page. My problem is that while some bits of the URL need replacing to make it work, others need to be left as they are.
The title for the pages are in the URL e.g. this page has the title "IDIOTS OR WHAT?!"
http://www...../mim_forums_homepage-user/mim_forums_thread.htm?masterID=195&forumID=281&sta rtPos=0&title=<b>IDIOTS%20OR%20WHAT?!</b>
I need a way to replace the punctuation in the titles into hex equivilents without changing the beginning of the URL. E.g. i need to change the ?! at the end into %3F%21 without changing the ? before the URL parameter.
Also, the titles are different for everypage, some titles might have ??? or !!! or ?!?! or ... etc. in them so ideally one bit of code to deal with all eventuallities. Is there a way that i can specify to just replace characters inside the &title= bit?
Expand|Select|Wrap|Line Numbers
- <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("<b>", "%3Cb%3E");
- var page_url = page_url.replace("</b>", "%3C/b%3E");
- 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>
Adele x