accessing javascript objects from another frame

  • Thread starter Halldór Ísak Gylfason
  • Start date
H

Halldór Ísak Gylfason

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.getElementById("IFrameId").document.a

but that didn't work. By the way, I am using IE.
 
L

Lasse Reichstein Nielsen

basically I have an IFrame inside the top frame. The document in
IFrame defines a javascript object:
var a = new Table();

I assume that is a global variable of the IFrame document. That
is, it is a property of its window object.
in the top level frame I want to access this object. I tried doing

document.getElementById("IFrameId").document.a

but that didn't work. By the way, I am using IE.

In IE, you can write
document.getElementById("IFrameID").contentWindow.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 ".contentDocument" property, but it won't allow
you to access a global variable of the iframe.

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

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,219
Latest member
Geraldine7

Latest Threads

Top