473,803 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing href text

I have a page that contains several HREFs. Each HREF that I'm
interested in has a common parameter (parmX). Does anyone have a script
example on how to find-and-replace parmX with parmY?

I'm assuming that I'd need to do this in the onload event - but I don't
know much about Javascript.

Please Help!

Thanks
Glenn

Jan 26 '06 #1
8 4353
wrote on 26 jan 2006 in comp.lang.javas cript:
I have a page that contains several HREFs. Each HREF that I'm
interested in has a common parameter (parmX). Does anyone have a script
example on how to find-and-replace parmX with parmY?

I'm assuming that I'd need to do this in the onload event - but I don't
know much about Javascript.


<a href='...'>...</a> usually contains just a URL.

Do you mean that?

Show us some code, the relevant part, that is.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #2
Yes - thats what I mean. The URL in the <a Href= tag may contain a
parameter &amp;stream= 1. I want to replace every occurrence of that
with a new parameter &amp;stream= 0.

I wrote a test script:

OnLoad() {
var frm = document.forms[0];
var cnt = 0;

// loop through all elements
for (i=0; i<frm.length; i++) {

// Look for hrefs with the stream=1 parameter
if (frm.elements[i].name.indexOf(' &amp;stream= 1') != -1) {
cnt = cnt + 1;
alert('Found HREF w/stream=1[' + cnt + ']');
}
}
}
return;
}

Followed by a call to the function in the Body Onload event

</head>

<body onload="OnLoad( );" marg...

However, I'm getting an error - so I assume that my syntax or something
is wrong. I just wanted to start trying to access the function and
report on hits. I'll have to tackle the data replacement once I get
over this hurdle...

Thanks
Glenn

Jan 26 '06 #3
go****@nixonpea body.com wrote:
Yes - thats what I mean.
What is what you mean?
The URL in the <a Href= tag may contain a parameter &amp;stream= 1. I want to replace every occurrence of that
with a new parameter &amp;stream= 0.

I wrote a test script:

OnLoad() { Bad name for a function

function searchHrefForSt r(Str){ var frm = document.forms[0]; Surely you mean "document.links " ?

var cnt = 0;

// loop through all elements
for (i=0; i<frm.length; i++) { for(var i=0;i<document. links.length;i+ +){


// Look for hrefs with the stream=1 parameter
if (frm.elements[i].name.indexOf(' &amp;stream= 1') != -1) { if (document.links[i].href.indexOf(S tr) != -1{

cnt = cnt + 1; Not neccesary


alert('Found HREF w/stream=1[' + cnt + ']'); alert('Found HREF w/'+Str'+'[' + (cnt++) + ']');
}
}
}
return; why return? }

Followed by a call to the function in the Body Onload event

</head>

<body onload="OnLoad( );" marg... <body onload="searchH refForStr('stre am=1');"
Not tested.
Mick

However, I'm getting an error - so I assume that my syntax or something
is wrong. I just wanted to start trying to access the function and
report on hits. I'll have to tackle the data replacement once I get
over this hurdle...

Thanks
Glenn

Jan 26 '06 #4
mick white wrote on 26 jan 2006 in comp.lang.javas cript:
go****@nixonpea body.com wrote:
Yes - thats what I mean.


What is what you mean?
The URL in the <a Href= tag may contain a
parameter &amp;stream= 1. I want to replace every occurrence of that
with a new parameter &amp;stream= 0.

[...........]


Let's make this compact:

=============== ===========
<script type='text/javascript'>
hrefChange(){
for( h in document.links )
h.href=h.href.r eplace(/[\?\&]stream=0(\&||$)/,'$1stream=1$2' )
}
</script>

<body onload='hrefCha nge()'>
.....
=============== ===========

Not tested
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #5
Evertjan. wrote:
mick white wrote on 26 jan 2006 in comp.lang.javas cript:
go****@nixonp eabody.com wrote:

Yes - thats what I mean.


What is what you mean?
The URL in the <a Href= tag may contain a
parameter &amp;stream= 1. I want to replace every occurrence of that
with a new parameter &amp;stream= 0.


[...........]

Let's make this compact:

=============== ===========
<script type='text/javascript'>
hrefChange(){
for( h in document.links )
h.href=h.href.r eplace(/[\?\&]stream=0(\&||$)/,'$1stream=1$2' )
}
</script>

<body onload='hrefCha nge()'>
....
=============== ===========

Not tested

Very good, not sure that will replace "&amp;" though.
Mick
Jan 26 '06 #6
mick white wrote on 26 jan 2006 in comp.lang.javas cript:
Evertjan. wrote:
mick white wrote on 26 jan 2006 in comp.lang.javas cript:
go****@nixon peabody.com wrote:
Yes - thats what I mean.

What is what you mean?
The URL in the <a Href= tag may contain a

parameter &amp;stream= 1. I want to replace every occurrence of that
with a new parameter &amp;stream= 0.

[...........]

Let's make this compact:

=============== ===========
<script type='text/javascript'>
hrefChange(){
for( h in document.links )
h.href=h.href.r eplace(/[\?\&]stream=0(\&||$)/,'$1stream=1$2' )
}
</script>

<body onload='hrefCha nge()'>
....
=============== ===========

Not tested

Very good, not sure that will replace "&amp;" though.


If you are not sure, why not test it, it's your code anyway.

&amp; should not be necessary in the result, so try:

/[\?\&](amp;)?stream=0 (\&||$)/
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #7
Evertjan. wrote:
mick white wrote on 26 jan 2006 in comp.lang.javas cript:

Evertjan. wrote:

mick white wrote on 26 jan 2006 in comp.lang.javas cript:
go****@nixo npeabody.com wrote:

>Yes - thats what I mean.

What is what you mean?
The URL in the <a Href= tag may contain a
>paramete r &amp;stream= 1. I want to replace every occurrence of that
>with a new parameter &amp;stream= 0.

[...........]
Let's make this compact:

============ ==============
<script type='text/javascript'>
hrefChange(){
for( h in document.links )
h.href=h.href.r eplace(/[\?\&]stream=0(\&||$)/,'$1stream=1$2' )
}
</script>

<body onload='hrefCha nge()'>
....
============ ==============

Not tested

Very good, not sure that will replace "&amp;" though.

If you are not sure, why not test it, it's your code anyway.


It's not my code...
Mick
&amp; should not be necessary in the result, so try:

/[\?\&](amp;)?stream=0 (\&||$)/

Jan 26 '06 #8
Evertjan -

Thanks for the help! I really appreciate the code example.

I'll test it today and let you know it works.

Glenn

Jan 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2602
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ... What a horrible can of worms regex is!! (to the uninitiated at least). I realise that if I spend the next few weeks researching regex I'll probably find the answer but I was wondering if anyone here would kindly help speed up the process?
8
1606
by: jamesfin | last post by:
Dear XMLers, Please guide me... I have a simple xml file... <URLTest>
1
1762
by: Martijn Berendsen | last post by:
Hello! Example: <a href="www.abc.com">ABC</a> <a href="www.xyz.com">www.xyz.com</a> I'm looking for a script that replaces the part within the HTML tag (www.abc.com and www.xyz.com) with another link (in my case a redirect), without affecting the part with "www.xyz.com: enclosed by the tags.
14
3770
by: Adnan Siddiqi | last post by:
Hi Suppose I have following URLs comming from an HTML document <a href="http://mydomain1.com">Domain1</a> <a href="http://subdomain.domain.com/myfile.anyext">http://subdomain.domain.com/myfile.anyext</a> <a href="http://subdomain.domain2.com/myfile.anyext">Domain2</a>
2
6548
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP skills are quite basic so far, far from proficient at this. ..htaccess file- DirectoryIndex default.php index.asp index.html index.htm index.php
1
2354
by: gViscardi | last post by:
Hello all, Ok, so what I am attempting to accomplish is to replace my table-based website with a CSS layout site, but I have run into a few hitches. My main problem is that currently my website has sliced images that form the frame around some text, I take those slices and put them into a table and everything comes out fine. My table has three rows, the first row has 5 cells, each containing a piece of the frame, with the 2nd cell...
1
2562
by: cma6 | last post by:
I have a page which uses tables for layout http://www.vintagetextile.com/1920s_to_1930s.htm The checkerboard pattern is achieved with this markup: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>1920s to 1930s high-style Vintage Clothing at Vintage Textile</title>
1
1411
by: Ivann | last post by:
Hi All, I have a javascript/css menut that i have which i start when the html page loads. <script type="text/javascript">cssdropdown.startchrome("chromemenu")</ script> ***THIS IS IN THE BODY***** What i am trying to do is replace the text inside of a div <alink.
1
2653
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming from C/C++ background, it looks like a functional language I'm not familiar with. Here's the link to where I got the code (thanks goes to the author), but I don't have a strong enough background in xsl to tell what is going on. xslfile.xsl ...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
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
10289
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
10068
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
7600
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
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
3
2968
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.