#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    madrid, spain
    Posts
    17
    Rep Power
    0

    swapping an image in a layer


    Because NS4 think of a layer like a new document (page) it don't allow me to swap an image that it's contained in a layer.
    I have a imgwap function like this:

    function swapimg(imgname, newsrc, nestdiv)
    {
    if (NS) {
    document.layers[nestdiv].document.images[imgname].src = newsrc;
    } else {
    document.images[imgname].src = newsrc;
    }
    }

    where "nestdiv" is the div that contains the image I want to swap.

    I've heard something about "document.layers['container']" but I'm not sure how to use it.

    Also, I have another issue. Why my pages don't use the cache. I mean, if an image has been downloaded yet why the browser tries to get it again when I do a rollover. I've created a image preloader but it seems to be useless.

    Can anybody help me?
    Thanks in advance
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    madrid, spain
    Posts
    17
    Rep Power
    0
    I discovered how to do it, see the following function:

    function swapimg(imgname, newsrc, nestdiv)
    {
    if (NS && nestdiv) {
    document.layers[nestdiv].document.images[imgname].src = newsrc;
    } else {
    document.images[imgname].src = newsrc;
    }
    }

    where imgname is the name of the image, newsrc is the new url for the image and nestdiv is the layer (the css id, i mean the #) where the image is contained.

    it works in IE4+ & NS4+ included NS6).

IMN logo majestic logo threadwatch logo seochat tools logo