Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    God's own country
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing img source inside a layer in NN

    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.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    because it's inside a layer you need to refer to it by
    document.layers[layername].images[imageID].src=path;

    try that

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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[i++]) {
    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();
    other routines;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •