Web Analytics Made Easy -
StatCounter Changing img source inside a layer in NN - CodingForum

Announcement

Collapse
No announcement yet.

Changing img source inside a layer in NN

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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.
    The best way to make your dreams come true is to WAKE UP . . . !!!

  • #2
    because it's inside a layer you need to refer to it by
    document.layers[layername].images[imageID].src=path;

    try that

    Comment


    • #3
      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;
      }

      Comment

      Working...
      X