inspecting the iframe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • herc777@hotmail.com

    inspecting the iframe

    Is it possible for javascript to inspect the contents of an iframe or
    is it an external object?

    <iframe id="myiframe" src="">

    <script>
    document.getEle mentById.myifra me.src =
    "http://www.wherever.co m/foo.php"
    </script>

    I can set the src of the iframe from javascript, can I read the
    results, assuming the iframe returns some text?

    like with frames you can nest the document object,
    mytext = document.getEle mentById.myifra me.document.bod y

    Herc

  • Richard Cornford

    #2
    Re: inspecting the iframe

    herc777@hotmail .com wrote:[color=blue]
    > Is it possible for javascript to inspect the contents
    > of an iframe or is it an external object?[/color]

    So long as cross-domain security restrictions don't apply, it is
    possible to access the window object within an IFRAME through the -
    frames - collection of the containing window object.
    [color=blue]
    > <iframe id="myiframe" src="">[/color]

    However, of you want to access IFRMAE content through the - frames -
    collection as a named property of the collection you would be better off
    giving the IFRAME an additional name attribute that correspo0nds with
    its ID.
    [color=blue]
    > <script>[/color]

    Valid HTML 4 requires SCRIPT elements to have a TYPE attribute.
    [color=blue]
    > document.getEle mentById.myifra me.src =[/color]

    It is extremely unlikely that the function object that is the
    getElementById method of the document will have a property named
    'myiframe'. You should be calling the getelementById method at this
    point an passing the ID of the element to it as a string.
    [color=blue]
    > http://www.wherever.com/foo.php[/color]

    By W3C HTML DOM standard assigning a value to the - src - property of an
    IFRAME is a meaningless and pointless activity (i.e. cannot be expected
    to provide useful or consistent results across DOM standard browsers
    (and doesn't)). Navigating IFRAMEs is best done by assigning to the -
    location - property of their correspo0nding window object.
    [color=blue]
    > </script>
    >
    > I can set the src of the iframe from javascript,[/color]

    But you probably shouldn't expect that to do anything useful.
    [color=blue]
    > can I read the
    > results, assuming the iframe returns some text?
    >
    > like with frames you can nest the document object,
    > mytext = document.getEle mentById.myifra me.document.bod y[/color]

    frames['myiframe'].document.body

    - assuming you give the IFRAME a NAME attribute of "myiframe".

    Richard.


    Comment

    • herc777@hotmail.com

      #3
      Re: inspecting the iframe

      This is how I was running a basic shoutbox

      document.getEle mentById("if1") .src =
      "http://www.ch3ss.com/test/chat.php?say=" + document.chat.s ay.value

      chat.php just adds the say.value to a text file and echoes the file.
      (its offline now incase people send it junk).

      I can't seem to get frames["myiframe"}.doc ument.body to return
      anything, Access is denied, I tried changing permissions.

      Herc

      Comment

      Working...