View Full Version : access array in iframe[RESOLVED]

02-02-2007, 05:07 PM

in my parent window I have an array called comments. It holds either a 1 or 2 to tell me whether there are comments for an image or not.

In my iframe called 'myframe' I need to check what is in a single element of my array. How do I do this?

FOr example, here is what I have

in my parent window there is a var called 'imageon' that holds a sequential number 1-15 so if imageon held 4 then comments[imageon] would tell me whether image 4 has comments or not. This works in my parent window but I need to access this in my iframe.

So I have tried

if (parent.document.comments[parent.document.imageon] == 1)

if (parent.comments[parent.imageon] == 1)

I am not sure how to do this. I tried a simple alert from teh iframe and I can alert the var imageon but when I try to alert(parent.comments[4]), I get an error. SO I assume you access array variables differently.

Any help with this would be great. Thanks

02-02-2007, 06:13 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml">

<script language="JavaScript" type="text/javascript">
var Ary=['tom','Dick','Harry'];

<iframe name="Tst1" src="if1.htm" width="200" height="200"></iframe>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script language="JavaScript" type="text/javascript">

function Init(){



<body onload="Init();">



02-02-2007, 06:19 PM
Thanks for the reply VW.

It looks like our differences is that you have window.parent.ary[1] as opposed to parent.ary[1]

I tried this

alert(window.parent.comments[2]); in my iframe

And I get an error that says
window.parent.comments.2 is null or not an object. But I can alert comments[2] on my parent page. It holds a value. Also I am not sure why the error is saying comments.2 and not comments[2].

Any ideas?

Ultimately I need to know what comments[parent.imageon] holds.

A live example of what I am doing is here Test page (http://www.photogap.net/common/igallery.php) After the page, loads, just click on any of the thumbnails, the onclick calls a function that has this alert in it.

Thanks again for your time

02-02-2007, 08:09 PM
your comment arry appears to be local

make it global(specified outside the function) and it will be accessable

var comments = new Array();
function next_back(action)

var image_list = new Array();
image_list[1] = 1;
comments[1] = 2;
image_list[2] = 2;
comments[2] = 2;
image_list[3] = 3;
comments[3] = 2;

02-02-2007, 08:22 PM
That did it! THanks a lot.