...

View Full Version : Changing img source inside a layer in NN



Haris
07-10-2002, 03:46 PM
Hi there,
When i try to change the source of an image, which is placed in a layer(DIV tag),it works only in IE. It doesn't work in Netscape. I am using NN 4.7.My code is like this

document.images[imageID].src=path;

when i tried alert(document.images[imageID]); it shows 'undefined' in NN.

It works fine in both the browsers without a DIV tag.Can anybody please tell me how to solve this problem.....


Thanks,
Haris.

tamienne
07-10-2002, 04:34 PM
because it's inside a layer you need to refer to it by
document.layers[layername].images[imageID].src=path;

try that

adios
07-11-2002, 12:04 AM
tamienne's solution is fine; if you're dealing with a bunch of images, you might want to try this:

<script type="text/javascript">

function NS_flattenImageRefs() {
if (!document.layers || !document.layers.length) return;
var currImg, i;
for (var l=0; l<document.layers.length; ++l) {
i = 0;
while (currImg = document.layers[l].document.images) {
if (currImg.name) {
document.images[currImg.name] = currImg;
document[currImg.name] = currImg;
}
}
}
}

onload = NS_flattenImageRefs;

</script>

Run that in your page; it should straighten things out (unless your layers are nested - ugh). If you're already using the onload handler you'll need to do this:

onload = function() {
NS_flattenImageRefs();
[i]other routines;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum