Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Replace certain words on an entire page

Reply
Thread Tools

Replace certain words on an entire page

 
 
chadhuntley@gmail.com
Guest
Posts: n/a
 
      08-01-2007
I've been trying to figure this out without much luck. It doesn't seem
like it should be to difficult, but I just can't even find where to
start.

What I'm trying to do is to have javascript look through an entire
page (its entire source), find all instances of a word I assign, and
not display that word.

What I was even thinking about doing was taking the entire source,
from <html> to </html>, placing it into a string, and somehow using
replace().

Does anyone have a script for this? Or walk me through it?

 
Reply With Quote
 
 
 
 
jamie.ly@gmail.com
Guest
Posts: n/a
 
      08-01-2007
On Aug 1, 12:22 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> I've been trying to figure this out without much luck. It doesn't seem
> like it should be to difficult, but I just can't even find where to
> start.
>
> What I'm trying to do is to have javascript look through an entire
> page (its entire source), find all instances of a word I assign, and
> not display that word.
>
> What I was even thinking about doing was taking the entire source,
> from <html> to </html>, placing it into a string, and somehow using
> replace().
>
> Does anyone have a script for this? Or walk me through it?


document.getElementsByTagName('html')[0].innerHTML =
document.getElementsByTagName('html')[0].innerHTML.replace ( /myword/,
'my replacement' );

might work, or else try replace 'html' with 'body'

 
Reply With Quote
 
 
 
 
chadhuntley@gmail.com
Guest
Posts: n/a
 
      08-01-2007
On Aug 1, 1:58 pm, (E-Mail Removed) wrote:
>
> document.getElementsByTagName('html')[0].innerHTML =
> document.getElementsByTagName('html')[0].innerHTML.replace ( /myword/,
> 'my replacement' );
>
> might work, or else try replace 'html' with 'body'



I ended up using 'body' and it worked out great. Thanks!

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      08-01-2007
In comp.lang.javascript message <(E-Mail Removed)
oglegroups.com>, Wed, 1 Aug 2007 16:22:41, "(E-Mail Removed)"
<(E-Mail Removed)> posted:
>I've been trying to figure this out without much luck. It doesn't seem
>like it should be to difficult, but I just can't even find where to
>start.
>
>What I'm trying to do is to have javascript look through an entire
>page (its entire source), find all instances of a word I assign, and
>not display that word.
>
>What I was even thinking about doing was taking the entire source,
>from <html> to </html>, placing it into a string, and somehow using
>replace().
>
>Does anyone have a script for this? Or walk me through it?


Here's a possible start, replacing "number"; but note that the code
replaces the word in itself too.

document.body.innerHTML =
document.body.innerHTML.replace(/number/g, "")

Tested briefly in IE6 js-quick only.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-02-2007
Dr J R Stockton wrote on 01 aug 2007 in comp.lang.javascript:

> Here's a possible start, replacing "number";
>
> document.body.innerHTML =
> document.body.innerHTML.replace(/number/g, "")
>


> but note that the code
> replaces the word in itself too.


Use:

document.body.innerHTML =
document.body.innerHTML.replace(/(num)ber/g, "")

===========

Warning: the above will also change:

<input name='numberEight'>
to
<input name='Eight'>

and even uncheck [IE7]:
<input type=checkbox name=number checked>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace stop words (remove words from a string) BerlinBrown Python 6 01-17-2008 02:37 PM
Non-noise words are incorrectly recognised as noise words. Peter Strĝiman ASP .Net 1 08-23-2005 01:26 PM
Replace all words on a page gregpinero@gmail.com Javascript 3 08-10-2005 09:59 PM
replace words with bold words Lasse Edsvik ASP General 9 10-07-2003 01:19 PM



Advertisments