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

07-10-2002, 02: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


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.....


07-10-2002, 03:34 PM
because it's inside a layer you need to refer to it by

try that

07-10-2002, 11:04 PM
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;


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() {
[i]other routines;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum