PDA

View Full Version : java script code - replace image ?


DJXP
Sep 28th, 2005, 11:06 PM
Is there a way to write a java code that will replace an image later on the page with the one I want instead. (phrased oddly, sorry)

ie.


Picture http://personal.atl.bellsouth.net/t/h/the_mac/My_Adventures/New_York/homer_intel.jpg

is displayed on the bottom footer of all my webpages. I want to change this picture to be
http://www.upgradesource.com/pc/maxforce1/athlon64logo.gif

instead.

I can't delete anything, but I can add extra coding if needed. So is it possible to add coding that will allow image x to display image y instead ?

I will try to rephrase this better soon.

Thanks for any suggestions/help.

temporalillusion
Sep 28th, 2005, 11:23 PM
Certainly an odd request.. :)

So you can add to the code of a page but can't delete code?

If the tag has a name attribute, you can do some javascript like this:

function movepic(img_name,img_src)
{
document[img_name].src=img_src;
}

Then just call it with the name of the image and the source of the new image. If the image doesn't have a name, then you might be able to do some kind of CSS and layers to position it overtop or an IFRAME or something (not sure how to do that though off the top of my head).

DJXP
Sep 29th, 2005, 03:42 PM
yep, alternatively I have the option to just get rid of banner image all together, but im clueless on how I would go about doing that as well.

the name of the image itself is banner.gif , and is not on the same webserver as everything else is.

I checked if it had an img name , but no dice :-/

also the problem that would be if I had a name for the image that in order for that function to trigger id need to do something like this:
- wont let me write the code proper, but basically what im saying.

a onmouseover="movepic('img_name','img_src')">
img name="stupid image i want to remove" src="banner.gif"> /a


Something I forgot to mention is I can't add code after the image, so I can't add the /a

what im thinking is there needs to be a code that will replace the any image named banner.gif with the image I want.

so when the browser reads the page, it will run a script replacing any banner.gif files shown with an alternative picture. hmmm...

Also there are no frames on the page.

temporalillusion
Sep 29th, 2005, 07:06 PM
Yeah I guess you could write some javascript that would get all the child objects on the DOM and iterate through them and try to find the image.

That's highly ineffecient though, and may work differently on different browsers. And wouldn't work at all for anyone that's disabled javascript.

Sounds like the kind of job to walk away from with all those restrictions.

DJXP
Sep 29th, 2005, 08:53 PM
yep this ones got me puzzled. it only has to work in ie , other browsers arent a concern.

I will have to relearn my coding, been so many years, but its slowly coming back.

thanks for the suggestions :)