473,770 Members | 4,055 Online
Bytes | Software Development & Data Engineering Community
+ 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_home page-user/mim_forums_thre ad.htm?masterID =195&forumID=28 1&startPos=0&ti tle=<b>IDIOTS%2 0OR%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 1871
acoder
16,027 Recognized Expert Moderator MVP
Try using encodeURICompon ent().
Mar 27 '08 #2
adelemb
6 New Member
Try using encodeURICompon ent().
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
10200
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 filter() { var items = new Array("John", "Jane");
8
4066
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 problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
5
2720
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 shall provide the same interface for the fortran code calling the library. Fortunately, this works - currently under WinNT - well for all functions which do not return a string, e.g.
5
2638
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* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
19
78835
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 find one.
16
6165
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 = @Scenario" Dim cmdstr as String cmdstr = cmdTestResourcesSel
6
7610
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, Karthi
3
3503
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 read in msdn : and notice that trim only Removes all occurrences of white space characters from the beginning and end of this instance. So what for the middle ? .NET Framework Class Library
10
18638
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 parameter with which you can write wanted character at that position. But no, Replace method only allows replacing one known character with another. The problem is I don't know the character to replace, just must replace the character at a known...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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 we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.