#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4

    Reflect Javascript array content update from one frame to another one


    Hi Guys,

    1-I have two frames in my page Frame 1 and frame 2
    frame 1 holds a tag where i pull a java script array A1 value items but it is static and it is at the top of my page.

    2-The second frames can be the content of different forms. One of the forms allows me to re-run the query i am using to fill my javascript array A1, so automatically the A1 contents will change.
    My question is :

    How to get new element added in 2 in my javascript array A1 showing in the Frame 1 ?.

    In other terms the javascript is being updated in frame 2 and i want to see those updates in frame 1 tag.

    Thanks for your help
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,176
    Rep Power
    184
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    9
    Rep Power
    0
    I don't think you can do it that way. I would move the array into the parent of the frames (aka the page that you declare the iframes on). Then from each iframe you can reference the array by doing window.parent.A1.
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,176
    Rep Power
    184
    Originally Posted by gsharp
    I don't think you can do it that way.
    Haha, I gave you a link to thousands of search results; with examples and demos, about javascript iframe communication and you say you don't think it can be done that way.

    Originally Posted by gsharp
    Then from each iframe you can reference the array by doing window.parent.A1.
    So if you got it figured out already; then what are you asking?
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    Originally Posted by web_loone08
    So if you got it figured out already; then what are you asking?
    The OP (original poster) is korssane. You're responding to gsharp who is saying that it's simpler to keep the array in the parent document.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,176
    Rep Power
    184
    Originally Posted by Kravvitz
    The OP (original poster) is korssane. You're responding to gsharp who is saying that it's simpler to keep the array in the parent document.
    Yeah, your right Kravvitz... my fault korssane. I was working on something and trying to respond, at the same time. The point that I was making, was that the OP... could have found the solution by searching for "iframe communication"; which would have given a "remote control" iframe/parent.document communication and several other examples, such as: HTML5 postMessage - for a cross domain solution.

    At any rate... korssane, a basic example would be something like gsharp and Kravvitz is talking about; something such as:

    Parent Document

    Code:
    <script>
    function getArray(myArray)
    {
    alert(myArray);
    }
    </script>
    
    <iframe src="framed_page.html"></iframe>
    framed_page.html

    Code:
    <script>
    var demoArray = ["Hello korssane!"];
    </script>
    
    <a href="#" onclick="parent.getArray(demoArray[0]);return false">Click Me</a>
    In the basic example above; the document(s) must remain under the same domain, because of the Same-Origin (domain security) policy (most modern browsers implore). If you need a cross domain approach; you might want to look into "HTML5 postMessage", as I briefly mentioned above.
    Last edited by web_loone08; November 7th, 2012 at 07:10 PM.

IMN logo majestic logo threadwatch logo seochat tools logo