View Full Version : How to replace an image with a new one?
Sylver Cheetah 53
06-08-2010, 03:37 PM
Hi!
I want a code for replacing an image with another one.
Thanks!
davelf
06-09-2010, 02:03 AM
what do you mean? You need to more specific describing your problem.
Sylver Cheetah 53
06-09-2010, 01:33 PM
The picture from here (http://friendsforever.co.cc) (the logo).
I want to be different on a specific section of the forum, meaning here (http://friendsforever.co.cc/viewforum.php?f=25). As you can see, I've already put an image over, using this code:
<div style="position: absolute; top: 22px; left: 32px"><img src="http://friendsforever.co.cc/templates/fiblue3d/images/cellpic_fifa.jpg" border="0"></div>
But it's not an optimal solution.
I want a better solution. I've also tryed the following:
<script language="javascript">
var objDoc = document.getElementsByTagName('img')
var i
var newImage = 'http://friendsforever.co.cc/templates/fiblue3d/images/cellpic_fifa.jpg'
for (i=0; i<objDoc.length; i++) {
if (objDoc[i].src.match(/cellpic_bkg/)){
objDoc[i].src = newImage;
}
}
</script>
But it doesn't work.
tomywie
07-09-2010, 01:36 AM
could you specify your question a bit? there's many ways to do it..
example:
<a href="javascript:void(0)"><img onMouseDown="this.src='http://i29.tinypic.com/2rddiqt.jpg'" onMouseUp="this.src='http://i32.tinypic.com/124f21v.jpg'" onMouseOver="this.src='http://i32.tinypic.com/zoavrm.jpg'" onMouseOut="this.src='http://i32.tinypic.com/124f21v.jpg'" src="http://i32.tinypic.com/124f21v.jpg" /></a>
djr33
07-09-2010, 02:07 AM
I am also somewhat confused.
I think what you are asking about is a basic form of templating. You want one image in one location and another in another location.
There are two ways to do this:
1. Just create two copies of your code and use one for one page, and the other for another.
2. Use some programming language to replace the SRC of the image when in the other location. This cannot be done in HTML alone, or using CSS alone.
If you want to use a programming language, then you can try two options:
-Javascript: this requires that Javascript is available in the user's browser, and then you would check if the current URL contains the path like /mydirectory/; if so, change the SRC of the element by it's id. Using Javascript is possible for a beginner, perhaps the easiest way, but this code isn't exactly easy, though it's not very hard either. The hardest part is checking the URL to see if it contains the special directory.
-PHP or another serverside language: while generating the page, you can add an if statement to check if the page is within /mydirectory/ like above. Then you would either output the original path or change it if the special directory was found. This is fairly simple, but requires that your server supports PHP or another serverside language, and programming in a serverside language can be harder to understand if you've never done it before (but it's very useful to learn). This does NOT require anything special from the user, and it will be completely hidden.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.