accessing javascript objects from another frame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Halldór Ísak Gylfason

    accessing javascript objects from another frame

    Hello

    basically I have an IFrame inside the top frame. The document in
    IFrame defines a javascript object:

    var a = new Table();

    in the top level frame I want to access this object. I tried doing

    document.getEle mentById("IFram eId").document. a

    but that didn't work. By the way, I am using IE.
  • Lasse Reichstein Nielsen

    #2
    Re: accessing javascript objects from another frame

    hgylfason@calid ris.com (Halldór Ísak Gylfason) writes:
    [color=blue]
    > basically I have an IFrame inside the top frame. The document in
    > IFrame defines a javascript object:[/color]
    [color=blue]
    > var a = new Table();[/color]

    I assume that is a global variable of the IFrame document. That
    is, it is a property of its window object.
    [color=blue]
    > in the top level frame I want to access this object. I tried doing
    >
    > document.getEle mentById("IFram eId").document. a
    >
    > but that didn't work. By the way, I am using IE.[/color]

    In IE, you can write
    document.getEle mentById("IFram eID").contentWi ndow.a
    That won't work in all browsers, though. There is no standard that
    includes contentWindow. The DOM HTML specification only describe
    documents, so it has a ".contentDocume nt" property, but it won't allow
    you to access a global variable of the iframe.

    A more portable method is
    frames["IFrameID"].a

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Halldór Ísak Gylfason

      #3
      Re: accessing javascript objects from another frame

      Yep that worked. Thanks a lot!

      Regards, Halldor

      Comment

      Working...