PDA

View Full Version : image replacement via java script code ?



DJXP
09-28-2005, 11:12 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.

ChrisK
09-29-2005, 07:45 AM
Why can't you delete code?

DJXP
09-29-2005, 03:13 PM
thats irrevelavent to my question.

chief
09-29-2005, 03:37 PM
can't you just upload the pic to the server and just change the code to the a64 image name?

it's not deleting anything, just change...

ChrisK
09-29-2005, 04:18 PM
can't you just upload the pic to the server and just change the code to the a64 image name?

it's not deleting anything, just change...

Should work if the images are the same size.

DJXP
09-29-2005, 08:59 PM
no because i dont have access to the server where that image gets put on.
I can't edit/delete that information since its not set by myself. Also those images above are just for example sake.

basically I have my page of coding, then it goes to another server. whom uploads the page. At that point its tagged with an image. The only way to get rid of the image is if I then manually go and edit each one. This is a daily event though, and multiple pages, so its not feasible to keep editing it out. The server that uploads it can't help me because they don't know how to turn the feature off for one particular user, nor are they willing to figure it out. They have agreed that it is ok if I come up with a solution that does get rid of the image or replace it (or manually edit each one after :( ).

I automatically thought replacing it may be an easier task, because of the
movepic(img_name,img_src) type function. The problem with this is the image doesnt have a name :( I also can't add coding after the image since that is added in later by the server, so I cant complete a function like that since it wont have a "</a> to close it once triggered.

right now my thoughts are is there a way to

a) create a function that says find http://...banner.gif and make it show http://myserver/differentimage.gif

b) create a function that says find banner.gif and make it not show up on the brower.

The only browser I am concerned with is internet explorer. If the image shows up on other browsers still this is not so much of an issue.

Thanks for trying to help so far, hopefully this added information will help.

ChrisK
09-30-2005, 11:38 PM
Only thing I can suggest to you is to find a new host.

kibboy
10-02-2005, 10:08 PM
The code below will work if you have access to the <body> tag. Place this -
onload="chg_img();"inside your body tag and place the code below anywhere in the page. This has been tested in both IE and FireFox.




<script language=javascript>
function chg_img(){
//### Current location of the image starting from website root
img_loc = "/t/h/the_mac/My_Adventures/New_York/homer_intel.jpg";
//### New location of image can be absolute or relative
img_new_loc = "http://";
img_new_loc += "www.upgradesource.com/pc/maxforce1/athlon64logo.gif";
for(x=0;x<document.images.length;x++){
if(document.images[x].src.indexOf("://"))
img = document.images[x].src.substring(document.images[x].src.indexOf("/",9)).toLowerCase();
else
img = document.images[x].src.toLowerCase();

if(img_loc.toLowerCase() == img)
document.images[x].src = img_new_loc;

}
}
</script>


Let me know if you have any problems.

kibb

DJXP
10-20-2005, 03:07 PM
thanks kibb :) :) I will try that out

and Chris its nothing to do with my host or personal website, my actual site residence is seperate. ...I am not gonna bother explaining this further as its hard to understand. its a very weird/odd reason I need this done this specific way.

dbusguy
10-20-2005, 03:53 PM
DJXP, not sure if I fully understand, but let me give a suggestion which is sort of what you suggested as a possibility.

Can you put in a image name and host the image on a host like photobucket. Once the image is set up the first time, you will just have to go to photobucket and change the image using the same image name. The new image will show on your page without having to change the html code.

Will this work for you?

www.photobucket.com

DJXP
10-20-2005, 10:04 PM
Tim I am not completly sure how to use that coding...
lets say:



<html>
<head>sample header</head>
<body>

text blah blah blah
<script> insert the long scripting code in here </script>

text blah blah

<script> add onload function line ???? confused where to put this exactly</script>

<img src= image1.jpg></img>

</body></html>



DJXP, not sure if I fully understand, but let me give a suggestion which is sort of what you suggested as a possibility.

Can you put in a image name and host the image on a host like photobucket. Once the image is set up the first time, you will just have to go to photobucket and change the image using the same image name. The new image will show on your page without having to change the html code.

Will this work for you?

www.photobucket.com

nope i dont put the image on there, the service I submit my html code to strips my </body> and or </html> ending, adds some crucial info I need added, but also adds its little bit of info (tag info) and then closes the code. unfortunately they never thought to allow users to disable that , because the majority of people using this service would want people to know they use it.

Sorry I can't really mention the services etc :-/

kibboy
10-21-2005, 12:34 AM
Did you mean kibb as opposed to Tim? If so, you say that it strips the </body> tag. Does it strip the starting <body> tag as well? If not this will be your code -




<html>
<head >
<title>Sample Title in Header</title>
<script language=javascript>
function chg_img(){
//### Current location of the image starting from website root
img_loc = "/t/h/the_mac/My_Adventures/New_York/homer_intel.jpg";
//### New location of image can be absolute or relative
img_new_loc = "http://";
img_new_loc += "www.upgradesource.com/pc/maxforce1/athlon64logo.gif";
for(x=0;x<document.images.length;x++){
if(document.images[x].src.indexOf("://"))
img = document.images[x].src.substring(document.images[x].src.indexOf("/",9)).toLowerCase();
else
img = document.images[x].src.toLowerCase();

if(img_loc.toLowerCase() == img)
document.images[x].src = img_new_loc;

}
}
</script>
</head>

<body onload="chg_img();">

any text whatsoever.




<body></html>



4 things are needed for this code to work - you need the to input the url of the image you want to replace "img_loc", you need to input the new image location "img_new_loc", you need to place the javascript function in your head tag and you need to have access to the body tag to input the function call "chg_img();". I don't think you know javascript but unfortunetly I can't break it down much more than that.

If you don't have access to the opening <body> tag, there still may be other solutions.

kibb