PDA

View Full Version : Change a string of characters with aonether in a HTML file


r3ticul
01-20-2008, 05:46 PM
Hi all of you,

Problem:
~300 simple HTML files that have an common image somewhere in the body of the page, without span tags or id.
In all those files a have a <script src=".../ascript.js></script> in the body tag.
I can't change nothing else then the ascript.js file and I need to change the src of that image from all those 300 pages from the .js

I foud some information about a script that can find a specific string in the <body></body> of the page and change it automatically with the desired one, when the page loads, without needing IDs and Spans, but I didn't found the script itself.

I'll give you an example of how my html file looks:

<html>
<head>
</head>
<body>
<img src="files/asd.jpg">
<script src="scr/ascript.js></script>
</body>
</html>

So I can't change nothing in that page, just the ascript.js can be modified.

Any solutions?

r3ticul
01-20-2008, 07:14 PM
P.S.

I would want to change the entire "<img src=files/asd.jpg>" with something new

Kor
01-21-2008, 10:46 AM
could something like:

onload=function(){
var pics=document.getElementsByTagName('img'), i=0, p;
var newP='files/new.jpg';
while(p=pics[i++]){
if(p.src.match(/asd.jpg/g)){p.src=newP;break}
}

Bat, anyway, your onld picture will appear several seconds, while the page is loaded, and only after the complete loading of the document, the picture changes... There is nothing much to do about that...