Replace certain words on an entire page

Discussion in 'Javascript' started by chadhuntley@gmail.com, Aug 1, 2007.

  1. Guest

    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?
     
    , Aug 1, 2007
    #1
    1. Advertising

  2. Guest

    On Aug 1, 12:22 pm, "" <>
    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'
     
    , Aug 1, 2007
    #2
    1. Advertising

  3. Guest

    On Aug 1, 1:58 pm, 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!
     
    , Aug 1, 2007
    #3
  4. In comp.lang.javascript message <
    oglegroups.com>, Wed, 1 Aug 2007 16:22:41, ""
    <> 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.
     
    Dr J R Stockton, Aug 1, 2007
    #4
  5. Evertjan. Guest

    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)
     
    Evertjan., Aug 2, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Strøiman
    Replies:
    1
    Views:
    2,110
    Peter Strøiman
    Aug 23, 2005
  2. Richard Heathfield
    Replies:
    7
    Views:
    380
    Barry Schwarz
    Oct 5, 2003
  3. BerlinBrown
    Replies:
    6
    Views:
    4,643
  4. Lasse Edsvik

    replace words with bold words

    Lasse Edsvik, Oct 5, 2003, in forum: ASP General
    Replies:
    9
    Views:
    245
  5. Replace all words on a page

    , Aug 10, 2005, in forum: Javascript
    Replies:
    3
    Views:
    79
    McKirahan
    Aug 10, 2005
Loading...

Share This Page