Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   replacing text in a page (http://www.velocityreviews.com/forums/t931925-replacing-text-in-a-page.html)

prw 07-05-2007 01:35 AM

replacing text in a page
 
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


Lee 07-05-2007 05:50 AM

Re: replacing text in a page
 
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?


--


Evertjan. 07-05-2007 08:37 AM

Re: replacing text in a page
 
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)

RobG 07-05-2007 01:18 PM

Re: replacing text in a page
 
On Jul 5, 3:50 pm, Lee <REM0VElbspamt...@cox.net> 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


Dr J R Stockton 07-06-2007 05:11 PM

Re: replacing text in a page
 
In comp.lang.javascript message <Xns99646C000AC33eejj99@194.109.133.242>
, Thu, 5 Jul 2007 08:37:00, Evertjan. <exjxw.hannivoort@interxnl.net>
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.


All times are GMT. The time now is 01:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.