replacing text in a page

Discussion in 'Javascript' started by prw, Jul 5, 2007.

  1. prw

    prw Guest

    Hi. I'm trying to replace some text in a page via the location bar (in
    IE or Firefox). When I type in:

    javascript:document.body.innerHTML=document.body.innerHTML.replace("oldtext","newtext");

    The text is changed, but all formatting is lost also! Is there a way
    around this?

    Cheers,

    prw404
    prw, Jul 5, 2007
    #1
    1. Advertising

  2. prw

    Lee Guest

    prw said:
    >
    >Hi. I'm trying to replace some text in a page via the location bar (in
    >IE or Firefox). When I type in:
    >
    >javascript:document.body.innerHTML=document.body.innerHTML.replace("oldtext","newtext");
    >
    >The text is changed, but all formatting is lost also! Is there a way
    >around this?


    Your question doesn't make sense.
    You aren't really using "oldtext" and "newtext" as your
    parameters, are you? Does whatever you're really specifying
    as the replacement text contain formatting?


    --
    Lee, Jul 5, 2007
    #2
    1. Advertising

  3. prw

    Evertjan. Guest

    Lee wrote on 05 jul 2007 in comp.lang.javascript:

    > prw said:
    >>
    >>Hi. I'm trying to replace some text in a page via the location bar (in
    >>IE or Firefox). When I type in:
    >>
    >>javascript:document.body.innerHTML=document.body.innerHTML.replace("old
    >>text","newtext");
    >>
    >>The text is changed, but all formatting is lost also! Is there a way
    >>around this?

    >
    > Your question doesn't make sense.
    > You aren't really using "oldtext" and "newtext" as your
    > parameters, are you? Does whatever you're really specifying
    > as the replacement text contain formatting?


    .... and

    javascript replace expects a regex object as the first parameter.

    ..replace(/oldtext/,"newtext");

    .... and

    favelets shoud not return anything,
    so should be closed by appending something like:

    ;void 0;



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 5, 2007
    #3
  4. prw

    RobG Guest

    On Jul 5, 3:50 pm, Lee <> wrote:
    > prw said:
    >
    >
    >
    > >Hi. I'm trying to replace some text in a page via the location bar (in
    > >IE or Firefox). When I type in:

    >
    > >javascript:document.body.innerHTML=document.body.innerHTML.replace("oldtex t","newtext");

    >
    > >The text is changed, but all formatting is lost also! Is there a way
    > >around this?

    >
    > Your question doesn't make sense.


    I think the question makes sense, it just isn't a sensible thing to
    do. :)


    > You aren't really using "oldtext" and "newtext" as your
    > parameters, are you? Does whatever you're really specifying
    > as the replacement text contain formatting?


    Note to the OP: the replacement will occur in HTML tags, attribute
    names and their values as well as the actual content of the elements.
    e.g.: if you were to use your method to replace all the instances of
    'e' with 'i' say using:

    ...innerHTML = ...innerHTML.replace(/e/ig,'i');

    in the following:

    <p style="color: red;">Hello world!</p>

    you get:

    <p styli="color: rid;">Hillo world!</p>

    Extend that effect to an entire page and I think you see what's
    happening.


    --
    Rob
    RobG, Jul 5, 2007
    #4
  5. In comp.lang.javascript message <Xns99646C000AC33eejj99@194.109.133.242>
    , Thu, 5 Jul 2007 08:37:00, Evertjan. <>
    posted:
    >
    >javascript replace expects a regex object as the first parameter.
    >


    Expects, perhaps; but not requires. See ISO/IEC 16262 15.5.4.11 para 3.
    Try S = "abcabcabc".replace("b", 2+2) ; .

    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, Jul 6, 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. Brown Smith
    Replies:
    1
    Views:
    494
    Frankie
    Jun 25, 2005
  2. OB
    Replies:
    1
    Views:
    394
    Steve C. Orr [MVP, MCSD]
    Dec 2, 2005
  3. Tim_Mac
    Replies:
    2
    Views:
    595
    Tim_Mac
    Jan 21, 2006
  4. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    262
    Chris Hohmann
    Apr 11, 2005
  5. Andrew Poulos

    Finding and replacing text on a page

    Andrew Poulos, Apr 15, 2005, in forum: Javascript
    Replies:
    1
    Views:
    95
    Martin Honnen
    Apr 15, 2005
Loading...

Share This Page