Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    access array in iframe[RESOLVED]

    Hello,

    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

    Code:
    if (parent.document.comments[parent.document.imageon] == 1)
    also
    Code:
    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
    Last edited by tripwater; 02-02-2007 at 08:22 PM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    var Ary=['tom','Dick','Harry'];
    /*]]>*/
    </script></head>
    
    <body>
    <iframe name="Tst1" src="if1.htm" width="200" height="200"></iframe>
    </body>
    
    </html>
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function Init(){
     alert(window.parent.Ary[1])
    
    }
    
    /*]]>*/
    </script></head>
    
    <body onload="Init();">
    
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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
    Code:
    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 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
    Last edited by tripwater; 02-02-2007 at 06:24 PM.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    your comment arry appears to be local

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

    Code:
    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;
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    That did it! THanks a lot.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •