473,473 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replace function in URL, ignoring first instance of character

adelemb
6 New Member
Hi,

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
  1. <script type='text/javascript' language='JavaScript'>
  2. function jsMailThisUrl()
  3. {
  4. var email_subject = 'Check out this topic';
  5. var email_body = 'I found this topic and thought you might be interested: ';
  6. //var page_url = window.self.location.href.split( '?' )[0];
  7. var page_url=window.location.href;
  8. //page_url = page_url + '';
  9. var page_url = page_url.replace("<b>", "%3Cb%3E");
  10. var page_url = page_url.replace("</b>", "%3C/b%3E");
  11. var page_url = page_url.replace(/ /g, "%20");
  12. var field = document.email_friend_script.address;
  13. window.location = 'mailto:' + field.value + '?subject=' +
  14. escape( email_subject ) + '&body=' +
  15. escape( email_body + page_url + '\n\n');
  16. }
  17. </script> 
Thanks for your help!!!
Adele x
Mar 27 '08 #1
2 1861
acoder
16,027 Recognized Expert Moderator MVP
Try using encodeURIComponent().
Mar 27 '08 #2
adelemb
6 New Member
Try using encodeURIComponent().
Hi, thanks for this suggestion, Ill look into it (Google it) today :)
Mar 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
5
by: Michael Hiegemann | last post by:
Hello, I am unaware whether this is the right group to ask. Please point me to another forum if required. I would like to replace a Fortran function by one which is written in C. The function...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
16
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario =...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
10
by: Lonifasiko | last post by:
Hi, Just want to replace character at index 1 of a string with another character. Just want to replace character at that position. I thought Replace method would be overloaded with an index...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.