1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Nested iFrame problem

Discussion in 'HTML & JavaScript' started by minute80, Jan 18, 2009.

  1. minute80

    minute80 Regular Member

    Joined:
    Dec 3, 2008
    Messages:
    310
    Likes Received:
    81
    I am trying to access all iFrames on one page and modify their content, however:

    Code:
    var ifs = document.getElementsByTagName('iframe');
    for (i=0;i<ifs.length;i++) {
              alert(ifs[i].document.getElementsByTagName('iframe').length);
    }
    
    return same number of iframes as they are in root document (the actual situation is that root has two iframes, and frist iframe 5 iframes). This is on IE 7. Does anyone knows why?
     
  2. blackhat50

    blackhat50 Regular Member

    Joined:
    Oct 22, 2008
    Messages:
    336
    Likes Received:
    103
    Won't work, you have to use 1 iframe
     
  3. minute80

    minute80 Regular Member

    Joined:
    Dec 3, 2008
    Messages:
    310
    Likes Received:
    81
    Why it should not work? I can see the hierarchy when using window.frames method, however, when I try to set or get properties with that, script breaks down.
     
  4. minute80

    minute80 Regular Member

    Joined:
    Dec 3, 2008
    Messages:
    310
    Likes Received:
    81
    Ok, here is an update.This:

    Code:
    for (i=0;i<window.frames.length;i++) {
          for (j=0;j<window.frames[i].frames.length;j++) {
               for (k in window.frames[i].frames[j]) {
                    alert(k);
                }
           }
    }
    
    Reports window.frames.frames[j].document existance, however when I try to access the same property, script exits. Perhaps I have to mention, that some iFrames are cross domain. This doesn't work in FF 3 as well.
     
    Last edited: Jan 18, 2009