SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Firefox says the document.frames are undefined

    I'm having trouble with a bit of code that works with ie but does not seem to work with firefox. When lookin though the javascript console I discovered that firefox claimed that the document.frames part of the code was undefined. Here is some of the code relevant to the document.frames

    Code:
    document.write("<iframe name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>")
    
    function harvest()
    {
      var div = document.frames["index"].document.getElementsByTagName("div")
      for(var i = 0; i < div.length; i++)
          if(div[i].className == "thin")
              break
      var a = div[i].getElementsByTagName("A")
      var names = new Array(a.length)
      for(i = 0; i < a.length; i++)
          names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "")
      updateStatus(names)
    }
    why doesn't this work in firefox? Why is it undefined?

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The use of frames[] to address an array of iframe objects is IE-only. You can give your single iframe an id, then use getElementById(), or you can create your own array of iframe elements with getElementsByTagName().

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really don't know what I'm doing any more. My brain isn't working well and I have been playing with the code and I have realized that I don't know what I'm doing, this is what I have:
    Code:
    document.write("<iframe id='index' name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>")
    
    function harvest()
    {
      var div = document.getElementById("index").document.getElementsByTagName("div")
      for(var i = 0; i < div.length; i++)
          if(div[i].className == "thin")
              break
      var a = div[i].getElementsByTagName("A")
      var names = new Array(a.length)
      for(i = 0; i < a.length; i++)
          names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "")
      updateStatus(names)
    }
    I don't think I can apply what I have here. I knew it wouldn't work before I tried it. I don't know how to do what you have suggested.

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At first glance it looks like it might work if you fixed your syntactic errors: You're missing your curly braces for your for loops; The break command should be on the same line as your if conditional, if that what you're trying to trigger, or you could use curly braces there; It is really best practice to finish your statements with a semicolon.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... I still can't figure it out, and I'm doing things I shouldn't probably.

    Code:
    document.write("<iframe id='index' name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>");
    
    function harvest()
    {
      var div = document.getElementById("index").getElementsByTagName("div");
      {for(var i = 0; i < div.length; i++)
         if(div[i].className == "thin")break
      var a = div[i].getElementsByTagName("A");
      var names = new Array(a.length);}
      {for(i = 0; i < a.length; i++)
          names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "");}
      updateStatus(names);
    }
    my javascript console claims
    Code:
    div[i]
    has no properties

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't access the contents of an iframe like that.

    frames[] is not a collection of document; it's a collection of window.
    Code:
    window.frames["index"]
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  7. #7
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    window.frames[] is an array of frames; document.frames[], in IE, is an array of iframes.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kravvitz you are now my best friend... it worked, I also thank you JVLB, for all the time you spent helping me.

  9. #9
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome.

    Quote Originally Posted by JVLB
    window.frames[] is an array of frames; document.frames[], in IE, is an array of iframes.
    You're right. I forgot about that, sorry.

    When iframes are given a name (I'm not sure about id's) they are added to window.frames[] as well, which is why this works in this case.

    I like using window.frames[] because it works in IE4 and DOM1 browsers.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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