473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

change text: foo -> bar

I need some script that change "foo" to "bar" anywhere "foo" occurs on
the page once the page is loaded. Any idea how?
Jul 20 '05 #1
4 3348
Dan Diebolt wrote on 04 sep 2003 in comp.lang.javascript:
I need some script that change "foo" to "bar" anywhere "foo" occurs on
the page once the page is loaded. Any idea how?


IE:

<body onload='mybody.innerText=mybody.innerText.replace(/foo/g,"bar")'>
<div id="mybody">
blah foo<br>
blah foo
</div>
</body>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

<body onload='mybody.innertext=mybody.innertext.replace(/foo/g,"bar")'>
<div id="mybody">
blah foo<br>
blah foo
</div>
</body>

I don't have a <div> to grab "mybody" as a handle. I have to simply make
the change to whatever text is within <body>.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Dan Diebolt wrote on 04 sep 2003 in comp.lang.javascript:
<body onload='mybody.innertext=mybody.innertext.replace(/foo/g,"bar")'>
<div id="mybody">
blah foo<br>
blah foo
</div>
</body>

I don't have a <div> to grab "mybody" as a handle. I have to simply make
the change to whatever text is within <body>.


1/ It is not innertext, but innerText

2/ Why do you let yourself be constricted that way ? It seems you want to
change somone elses work. This could be unetical. The final p[ossibilitiy
is called "html-mining".

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4
da********@yahoo.com (Dan Diebolt) writes:
I need some script that change "foo" to "bar" anywhere "foo" occurs on
the page once the page is loaded. Any idea how?


Best guess is to run through the DOM tree:
---
function crawlDOM(node,fnode,ftext) {
switch (node.nodeType) {
case 1: // normal node
for(var i = 0;i<node.childNodes.length; i++) {
crawlDOM(node.childNodes[i],fnode,ftext);
}
fnode(node);
break;
case 3: // text node
ftext(node);
break;
}
}
---

Then you can do:
---
crawlDOM(document.body,
function (){},
function (tnode) {
tnode.nodeValue = tnode.nodeValue.replace(/foo/g,"bar");
});
---

You just have to pray that the document tree really is a tree :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

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

Similar topics

14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
34
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head>...
5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
3
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
5
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the text in the url/location bar?...
7
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to change the font color and weight at a specific position in the text. I am not sure where or what I need to do. It will be at position 155/156 from the left on each line. Here is the...
6
by: K Viltersten | last post by:
I have the following button: <asp:LinkButton id="Btn" runat="server" text="Click"> </asp:LinkButton> I have added an action listener in the javascript where I change the text on it:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
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...

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.