Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   replace instances of text on page with image or other text? (http://www.velocityreviews.com/forums/t881256-replace-instances-of-text-on-page-with-image-or-other-text.html)

juglesh 12-21-2004 06:54 PM

replace instances of text on page with image or other text?
 
Hello,

I need to look through the text on a page and replace certain words with an
image or other word

something like:

read document
find all instances of the word "blah"
change all instances of the word "blah" to <img src="MyPicture.jpg" >


(jeez, I don't get why computers cant just read english!<G>)
and, no, I cant just change the page with 'find/replace' in notepad.

--
thanks,
juglesh B>{)}



McKirahan 12-21-2004 07:14 PM

Re: replace instances of text on page with image or other text?
 
"juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
news:Sj_xd.302269$R05.120039@attbi_s53...
> Hello,
>
> I need to look through the text on a page and replace certain words with

an
> image or other word
>
> something like:
>
> read document
> find all instances of the word "blah"
> change all instances of the word "blah" to <img src="MyPicture.jpg" >
>
>
> (jeez, I don't get why computers cant just read english!<G>)
> and, no, I cant just change the page with 'find/replace' in notepad.
>
> --
> thanks,
> juglesh B>{)}
>
>


It is not clear -- who's page?

For any given URL do you want to change "certain words" and display it or
what?



juglesh 12-21-2004 07:38 PM

Re: replace instances of text on page with image or other text?
 

"McKirahan" <News@McKirahan.com> wrote in message
news:7C_xd.268087$HA.48168@attbi_s01...
> "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
> news:Sj_xd.302269$R05.120039@attbi_s53...
>> Hello,
>>
>> I need to look through the text on a page and replace certain words with

> an
>> image or other word
>>
>> something like:
>>
>> read document
>> find all instances of the word "blah"
>> change all instances of the word "blah" to <img src="MyPicture.jpg" >
>>
>>
>> (jeez, I don't get why computers cant just read english!<G>)
>> and, no, I cant just change the page with 'find/replace' in notepad.
>>
>> --
>> thanks,
>> juglesh B>{)}
>>
>>

>
> It is not clear -- who's page?


well, my .php is being included in their page(which they made for me) . my
..php page contains the head and the body tag, so i can put in a javascript,
and call it from body onload. basically, when it gets to your browser, you
see my head content, and most of the body is theirs.

>
> For any given URL do you want to change "certain words" and display it or
> what?


so, not any given url, just on the pages where my head content is used.

their page is:
<?php include 'http://www.mydomain.com/head.php'; ?>
<p> Welcome. Content is here. blah and blah</p>
</body>

my head.php is
<head>
<my javascript>
</head>
<body>

i want my js to change all instances of 'blah' to <img src="MyPicture.jpg" >

which would change the output to:
Welcome. Content is here. <the image> and <the image>





McKirahan 12-21-2004 09:04 PM

Re: replace instances of text on page with image or other text?
 
"juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
news:lZ_xd.689446$mD.299515@attbi_s02...
>
> "McKirahan" <News@McKirahan.com> wrote in message
> news:7C_xd.268087$HA.48168@attbi_s01...
> > "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
> > news:Sj_xd.302269$R05.120039@attbi_s53...
> >> Hello,
> >>
> >> I need to look through the text on a page and replace certain words

with
> > an
> >> image or other word
> >>
> >> something like:
> >>
> >> read document
> >> find all instances of the word "blah"
> >> change all instances of the word "blah" to <img src="MyPicture.jpg"

>
> >>
> >>
> >> (jeez, I don't get why computers cant just read english!<G>)
> >> and, no, I cant just change the page with 'find/replace' in notepad.
> >>
> >> --
> >> thanks,
> >> juglesh B>{)}
> >>
> >>

> >
> > It is not clear -- who's page?

>
> well, my .php is being included in their page(which they made for me) .

my
> .php page contains the head and the body tag, so i can put in a

javascript,
> and call it from body onload. basically, when it gets to your browser,

you
> see my head content, and most of the body is theirs.
>
> >
> > For any given URL do you want to change "certain words" and display it

or
> > what?

>
> so, not any given url, just on the pages where my head content is used.
>
> their page is:
> <?php include 'http://www.mydomain.com/head.php'; ?>
> <p> Welcome. Content is here. blah and blah</p>
> </body>
>
> my head.php is
> <head>
> <my javascript>
> </head>
> <body>
>
> i want my js to change all instances of 'blah' to <img src="MyPicture.jpg"
>
>
> which would change the output to:
> Welcome. Content is here. <the image> and <the image>
>


Will this work? Watch for word-wrap.

<head>
<script type="text/javascript">
function MyHead() {
var find = "blah and blah";
var repl = "<img src='MyPicture.jpg'>";
var page = document.body.innerHTML;
while (page.indexOf(find) >= 0) {
var i = page.indexOf(find);
var j = find.length;
page = page.substr(0,i) + repl + page.substr(i+j);
document.body.innerHTML = page;
}
}
</script>
</head>
<body onload="MyHead()">



McKirahan 12-21-2004 09:06 PM

Re: replace instances of text on page with image or other text?
 
make that:

var find = "blah";



juglesh 12-21-2004 10:15 PM

Re: replace instances of text on page with image or other text?
 

"McKirahan" <News@McKirahan.com> wrote in message
news:Wd0yd.540796$wV.495762@attbi_s54...
> "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
> news:lZ_xd.689446$mD.299515@attbi_s02...
>>
>> "McKirahan" <News@McKirahan.com> wrote in message
>> news:7C_xd.268087$HA.48168@attbi_s01...
>> > "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
>> > news:Sj_xd.302269$R05.120039@attbi_s53...
>> >> Hello,
>> >>
>> >> I need to look through the text on a page and replace certain words

> with
>> > an
>> >> image or other word
>> >>
>> >> something like:
>> >>
>> >> read document
>> >> find all instances of the word "blah"
>> >> change all instances of the word "blah" to <img
>> >> src="MyPicture.jpg"

>>
>> >>
>> >>
>> >> (jeez, I don't get why computers cant just read english!<G>)
>> >> and, no, I cant just change the page with 'find/replace' in notepad.
>> >>
>> >> --
>> >> thanks,
>> >> juglesh B>{)}
>> >>
>> >>
>> >
>> > It is not clear -- who's page?

>>
>> well, my .php is being included in their page(which they made for me) .

> my
>> .php page contains the head and the body tag, so i can put in a

> javascript,
>> and call it from body onload. basically, when it gets to your browser,

> you
>> see my head content, and most of the body is theirs.
>>
>> >
>> > For any given URL do you want to change "certain words" and display it

> or
>> > what?

>>
>> so, not any given url, just on the pages where my head content is used.
>>
>> their page is:
>> <?php include 'http://www.mydomain.com/head.php'; ?>
>> <p> Welcome. Content is here. blah and blah</p>
>> </body>
>>
>> my head.php is
>> <head>
>> <my javascript>
>> </head>
>> <body>
>>
>> i want my js to change all instances of 'blah' to <img
>> src="MyPicture.jpg"
>>
>>
>> which would change the output to:
>> Welcome. Content is here. <the image> and <the image>
>>

>
> Will this work? Watch for word-wrap.
>
> <head>
> <script type="text/javascript">
> function MyHead() {
> var find = "blah and blah";
> var repl = "<img src='MyPicture.jpg'>";
> var page = document.body.innerHTML;
> while (page.indexOf(find) >= 0) {
> var i = page.indexOf(find);
> var j = find.length;
> page = page.substr(0,i) + repl + page.substr(i+j);
> document.body.innerHTML = page;
> }
> }
> </script>
> </head>
> <body onload="MyHead()">


almost works! if i change repl to a different word, it will work (it will
display another word), but if i use that img tag, nothing changes.





juglesh 12-21-2004 10:52 PM

Re: replace instances of text on page with image or other text?
 

"juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
news:Lf1yd.612732$D%.496186@attbi_s51...
>
> "McKirahan" <News@McKirahan.com> wrote in message
> news:Wd0yd.540796$wV.495762@attbi_s54...
>> "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
>> news:lZ_xd.689446$mD.299515@attbi_s02...
>>>
>>> "McKirahan" <News@McKirahan.com> wrote in message
>>> news:7C_xd.268087$HA.48168@attbi_s01...
>>> > "juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
>>> > news:Sj_xd.302269$R05.120039@attbi_s53...
>>> >> Hello,
>>> >>
>>> >> I need to look through the text on a page and replace certain words

>> with
>>> > an
>>> >> image or other word
>>> >>
>>> >> something like:
>>> >>
>>> >> read document
>>> >> find all instances of the word "blah"
>>> >> change all instances of the word "blah" to <img
>>> >> src="MyPicture.jpg"
>>>
>>> >>
>>> >>
>>> >> (jeez, I don't get why computers cant just read english!<G>)
>>> >> and, no, I cant just change the page with 'find/replace' in notepad.
>>> >>
>>> >> --
>>> >> thanks,
>>> >> juglesh B>{)}
>>> >>
>>> >>
>>> >
>>> > It is not clear -- who's page?
>>>
>>> well, my .php is being included in their page(which they made for me) .

>> my
>>> .php page contains the head and the body tag, so i can put in a

>> javascript,
>>> and call it from body onload. basically, when it gets to your browser,

>> you
>>> see my head content, and most of the body is theirs.
>>>
>>> >
>>> > For any given URL do you want to change "certain words" and display it

>> or
>>> > what?
>>>
>>> so, not any given url, just on the pages where my head content is used.
>>>
>>> their page is:
>>> <?php include 'http://www.mydomain.com/head.php'; ?>
>>> <p> Welcome. Content is here. blah and blah</p>
>>> </body>
>>>
>>> my head.php is
>>> <head>
>>> <my javascript>
>>> </head>
>>> <body>
>>>
>>> i want my js to change all instances of 'blah' to <img
>>> src="MyPicture.jpg"
>>>
>>>
>>> which would change the output to:
>>> Welcome. Content is here. <the image> and <the image>
>>>

>>
>> Will this work? Watch for word-wrap.
>>
>> <head>
>> <script type="text/javascript">
>> function MyHead() {
>> var find = "blah and blah";
>> var repl = "<img src='MyPicture.jpg'>";
>> var page = document.body.innerHTML;
>> while (page.indexOf(find) >= 0) {
>> var i = page.indexOf(find);
>> var j = find.length;
>> page = page.substr(0,i) + repl + page.substr(i+j);
>> document.body.innerHTML = page;
>> }
>> }
>> </script>
>> </head>
>> <body onload="MyHead()">

>
> almost works! if i change repl to a different word, it will work (it will
> display another word), but if i use that img tag, nothing changes.


ahh, think i got it! i had to change my quotes in the img tag to single
quotes.

is find a special variable? if i wanted to find and replace some other
words, how could i do that without making a bunch more functions?

thank you very much.




RobB 12-22-2004 01:38 AM

Re: replace instances of text on page with image or other text?
 

juglesh wrote:
> Hello,
>
> I need to look through the text on a page and replace certain words

with an
> image or other word
>
> something like:
>
> read document
> find all instances of the word "blah"
> change all instances of the word "blah" to <img

src="MyPicture.jpg" >
>
>
> (jeez, I don't get why computers cant just read english!<G>)
> and, no, I cant just change the page with 'find/replace' in notepad.
>
> --
> thanks,
> juglesh B>{)}

Maybe...

http://www.alistapart.com/articles/dynatext/


McKirahan 12-22-2004 01:52 AM

Re: replace instances of text on page with image or other text?
 
"juglesh" <juglesh@nospamRadioKDUG.com> wrote in message
news:cP1yd.303759$R05.64258@attbi_s53...

[snip]

>
> ahh, think i got it! i had to change my quotes in the img tag to single
> quotes.
>
> is find a special variable? if i wanted to find and replace some other
> words, how could i do that without making a bunch more functions?
>
> thank you very much.



"var find" and "var repl" are just variable names.



Martin Bialasinski 12-22-2004 02:22 AM

OT: Re: replace instances of text on page with image or other text?
 
"juglesh" <juglesh@nospamRadioKDUG.com> wrote:

> read document
> find all instances of the word "blah"
> change all instances of the word "blah" to <img src="MyPicture.jpg" >
>
> (jeez, I don't get why computers cant just read english!<G>)


Well, it nearly looks like Applescript, which has a syntax like

tell application "Finder" to set x to entire contents of folder
"Macintosh HD:System Folder"

:-)


All times are GMT. The time now is 12:49 PM.

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