Change a string of characters with aoneter in a HTML file

Discussion in 'JavaScript' started by r3ticul, Jan 20, 2008.

  1. #1
    Hi all of you,

    Problem:
    ~300 simple HTML files that have an common image somewhere in 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, Jan 20, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try using document.images to find your inline image.

    Jay
     
    jayshah, Jan 20, 2008 IP
  3. akram

    akram Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <script>
    for(var i=0; i<document.images.length;i++) {
    if(document.images[i].src == "files/asd.jpg")
      document.images[i].src = "file/new_image.gif";
    }
    </script>
    
    
    HTML:

    Try the above code...
     
    akram, Jan 21, 2008 IP