Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > replacing text in a page

Reply
Thread Tools

replacing text in a page

 
 
prw
Guest
Posts: n/a
 
      07-05-2007
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.i nnerHTML.replace("oldtext","newtext");

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

Cheers,

prw404

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      07-05-2007
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?


--

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      07-05-2007
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)
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      07-05-2007
On Jul 5, 3:50 pm, Lee <(E-Mail Removed)> 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

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      07-06-2007
In comp.lang.javascript message <Xns99646C000AC33eejj99@194.109.133.242>
, Thu, 5 Jul 2007 08:37:00, Evertjan. <(E-Mail Removed)>
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.
 
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
regex for replacing plain text within html string... Tim_Mac ASP .Net 2 01-21-2006 12:13 AM
Replacing HTML text before rendering OB ASP .Net 1 12-02-2005 03:36 AM
Replacing the specific pattern of text in a huge text string.. Brown Smith ASP .Net 1 06-25-2005 05:34 AM
Finding and replacing text on a page Andrew Poulos Javascript 1 04-15-2005 11:30 AM
Replacing - and not Replacing... Rob Meade ASP General 5 04-11-2005 06:49 PM



Advertisments