|
-
Jun 18th, 2004, 06:01 AM
#1
Thread Starter
Member
JavaScript variables in frames [Resolved]
I need to access variables from a iframe.
I have a main frame which is the frameset and a content frame. In the main frame I have added a reference to a function
imges = null; // Single instance of class
function Imges() {
this.treeDashedPlus = null;
this.treeDashedMinus = null;
}
and added this in the body:
imges = new Imges();
imges.treeDashedMinus = '/images/tree/dashed/customminus.gif';
imges.treeDashedPlus = '/images/tree/dashed/customplus.gif';
on my content frame page I have a tree which when a node is clicked it calls a onTreeClick() javascript function, which has the following to set the node images
var imges = document.imges;
var src = node.collapsed ? imges.treeDashedMinus : imges.treeDashedPlus;
when I debug this the document.imges is shown as undefined.
What amd I doing wrong or is there another way to read variable from the main frame from within the content frame?
Last edited by Genie; Jun 21st, 2004 at 04:58 AM.
-
Jun 18th, 2004, 06:35 AM
#2
I'm not entirely sure if you can do it, as I haven't done much work in JS. I know you can use Functions of other frames, so I guess it would be the same method.
You need to specify the frame that contains the function (or data), for this you just use the name you used in the frameset.
eg:
if this is your frameset:
Code:
<FRAMESET>
<FRAME SRC="nav_frame.htm" NAME="nav">
<FRAME SRC="top.htm" NAME="top_frame">
</FRAMESET>
then to use functions in "nav_frame" from within "top" you would do this:
Code:
top.nav.function(param1,param2);
so I think you can do this:
[code]
var imges = top.framename.imges;
[code]
-
Jun 21st, 2004, 04:58 AM
#3
Thread Starter
Member
Thanks. I did something similar.
var imgs = window.parent.document.imgs;
all works ok.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|