"McKirahan" <> wrote in message
news:0qCzd.19336$k25.3159@attbi_s53...
> "juglesh" <> wrote in message
> news:Tf7zd.630520$D%.101935@attbi_s51...
>
> [snip]
>
>> thank you very much, this is perfect!!! One hint, don't try naming your
>> images the same as the word you are trying to replace<G>
> (blah1.gif-doesn't
>> work). throws IE into a tailspin.
>>
>> seems to run fast enough on my puter(xp, 2.8ghz, 512ram), do you think it
>> would be a problem on a lesser machine? at what point, x number of
> replaced
>> words, or x number of instances of the words in the page, would it be a
>> problem? I ask cuz it seems to me that we are storing the
>> document.body.innerHTML a lot. seems a lot of stuff to have in memory
> and
>> be looking thru multiple times, but I don't really know.
>>
>> --
>>
>> juglesh
>>
> Then let's only use it once:
>
> <head>
> <script type="text/javascript">
> function MyHead() {
> var list = new Array();
> list[0] = "blah1^<img src='MyPicture1.jpg'>";
> list[1] = "blah2^<img src='MyPicture2.jpg'>";
> list[2] = "blah3^<img src='MyPicture3.jpg'>";
> var j, k, find, item, repl;
> var page = document.body.innerHTML;
> for (var i=0; i<list.length; i++) {
> item = list[i].split("^");
> find = item[0];
> repl = item[1];
> page = document.body.innerHTML;
> while (page.indexOf(find) >= 0) {
> var j = page.indexOf(find);
> var k = find.length;
> page = page.substr(0,j) + repl + page.substr(j+k);
> }
> }
> document.body.innerHTML = page;
> }
> </script>
> </head>
> <body onload="MyHead()">
>
> Also, I'd suggest that instead of using "blah" use a tag-like reference
> such
> as [blah] si it will stand out more and can't be confused with an image
> name.
this last one isnt working here. only the third item is replaced.
I sorta see where you're going, though. you only do the
document.body.innerHTML = page at the end, and not through every for/while
loop? as you may have guessed, I'm just a copy/paste javascripter, I get
most of it, and if I squint at the code for long enough while flipping
through javascript references online, I can grok a bit more.
afa [blah] , do you mean that I should have the text to be replaced in the
html changed to bracketed? because that's why I'm going through all this in
the first place, I cant change most of the body of the page (well, not
without js).
--
juglesh
|