Replacing an image
|
|
Hello!! I have a simple question. How can I replace an image that I have in my computer by one that is in a web site? Both images have the same size (800x141) and name. This is the code. The image's path that is inside the red frame is the image I want to replace. http://img525.imageshack.us/img525/5919/captura... And this is my code: http://img365.imageshack.us/img365/2296/captura... But it's not correct. Any ideas? Thanks for helping ;). |
|
|
The source (src) of the frame might be expressed in the HTML with a relative path (vendetta/img/header_bg.jpg), but the actual "src" property, as determined by the web page, is always a full URL. So it's either a full path to a web page on a server (e.g. http://www.example.com/vendetta/img/header_bg.jpg) or an absolute path on your own computer (e.g. file:///C:/vendetta/img/header_bg.jpg). |
|
|
either one of these worked for me:
//the DOM way:
var allframe=document.getElementsByTagName('frame');
for(var i=0,ii=allframe.length;i<ii;i++) {
var header=allframe[i];
if(header.getAttribute('src').indexOf('vendetta/img/header_bg.jpg')!=-1) {
header.setAttribute('src','http://img294.imageshack.us/img294/2775/headerbgce1.jpg');
}
}
//or.... if you're xpath inclined:
var allframe=document.evaluate('//frame',document,null,XPathResult.ANY_TYPE,null);
header=allframe.iterateNext();
while(header) {
if(header.getAttribute('src').indexOf('vendetta/img/header_bg.jpg')!=-1) {
header.setAttribute('src','http://img294.imageshack.us/img294/2775/headerbgce1.jpg');
}
}
|
