How to add array elements to parent window from child window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markrandolph@juno.com

    How to add array elements to parent window from child window

    I have parent.htm and child.htm
    =============== =============== =============== =============== =====
    In parent.htm we have:

    var parentarray = new Array(5)
    window.open("ch ild.htm",.....)

    =============== =============== =============== =============== =====
    In child.htm I want to add new elements to parentarray, like
    opener.parentar ray[6] = .......
  • Conrad Lender

    #2
    Re: How to add array elements to parent window from child window

    On 2008-10-25 02:17, markrandolph@ju no.com wrote:
    In parent.htm we have:
    var parentarray = new Array(5)
    window.open("ch ild.htm",.....)
    In child.htm I want to add new elements to parentarray, like
    opener.parentar ray[6] = .......
    And your problem is...?


    - Conrad

    Comment

    • markrandolph@juno.com

      #3
      Re: How to add array elements to parent window from child window

      Actually here is a more accurate desc of the prob:

      parent.htm:

      function parentarrayobje ct(last,first)
      {
      this.last = last
      this.first = first
      }
      var parentarray = new Array()
      parentarray[0] = new parentarrayobje ct("sixpack","j oe") // this works
      ok
      window.open("ch ild.htm",.....)
      =============== =============== =============== =============== =====
      child.htm:
      //--the alert works, pops up with "object"
      alert(typeof(op ener.parentarra yobject))
      //--the next statement chokes... "Invalid procedure call or
      argument"
      opener.parentar ray[1] = new
      opener.parentar rayobject("five pack","jane")
      =============== =============== =============== =============== =====
      The problem is when trying to create parentarray[1] in child.htm it
      keeps giving "Invalid procedure call or argument"

      Comment

      • Conrad Lender

        #4
        Re: How to add array elements to parent window from child window

        On 2008-10-25 23:10, markrandolph@ju no.com wrote:
        Actually here is a more accurate desc of the prob:
        ...
        child.htm:
        //--the alert works, pops up with "object"
        alert(typeof(op ener.parentarra yobject))
        //--the next statement chokes... "Invalid procedure call or
        argument"
        opener.parentar ray[1] = new
        opener.parentar rayobject("five pack","jane")
        =============== =============== =============== =============== =====
        The problem is when trying to create parentarray[1] in child.htm it
        keeps giving "Invalid procedure call or argument"
        Your script is working fine, except in Internet Explorer (please mention
        that the next time!). Not sure what the cause is, except that it's not
        related to the array. It also occurs if you only write
        "new opener.parentar rayobject()". For some reason IE won't let you
        create objects from a constructor that was defined in the parent window.

        As a workaround, you could try calling a function in the opener, and
        have the new parentarrayobje ct created there.


        - Conrad

        Comment

        • SAM

          #5
          Re: How to add array elements to parent window from child window

          Le 10/25/08 2:17 AM, markrandolph@ju no.com a écrit :
          I have parent.htm and child.htm
          =============== =============== =============== =============== =====
          In parent.htm we have:
          >
          var parentarray = new Array(5)
          window.open("ch ild.htm",.....)
          >
          =============== =============== =============== =============== =====
          In child.htm I want to add new elements to parentarray, like
          opener.parentar ray[6] = .......

          And ?

          That doesn't work ?

          That would have to.

          --
          sm

          Comment

          • SAM

            #6
            Re: How to add array elements to parent window from child window

            Le 10/25/08 11:10 PM, markrandolph@ju no.com a écrit :
            Actually here is a more accurate desc of the prob:
            try :

            mother.htm :

            <script type="text/javascript">
            var tabl = [11,'hello',3];
            </script>
            </head>
            <body>
            <h1>parent</h1>
            <p><button onclick="window .open('child.ht m');">daughter</button>
            <button onclick="alert( tabl)">voir </button>


            child.htm :

            <body>
            <h1>children</h1>
            <form action="#"
            onsubmit="opene r.tabl.push(thi s.elemt.value); return false;">
            element to add : <input type="text" name="elemt">
            <input type="submit" value="add">
            </form>
            <form action="#"
            onsubmit="opene r.tabl[this.indx.value] = [
            this.val1.value ,
            this.val2.value
            ];
            return false;">
            index of element to modify : <input type="text" name="indx" size="5">
            value 1 : <input type="text" name="val1">
            value 2 : <input type="text" name="val2">
            <input type="submit" value="modify">
            </form>
            <button onclick="alert( opener.tabl)">s ee the opener's array </button>
            </body>


            works with IE and Fx
            --
            sm

            Comment

            • Conrad Lender

              #7
              Re: How to add array elements to parent window from child window

              On 2008-10-26 02:43, SAM wrote:
              onsubmit="opene r.tabl[this.indx.value] = [
              this.val1.value ,
              this.val2.value
              ];
              ...
              works with IE and Fx
              Sure, but it doesn't do what the OP was describing. It just adds an
              array to the array in opener, not a new object. As I said earlier, the
              array isn't the problem.

              Something along these lines might work (untested):

              // in parent:
              function Person (first, last) {
              this.first = first;
              this.last = last;
              }
              function addPerson (first, last) {
              persons.push(ne w Person(first, last));
              }
              var persons = [];
              persons.push(ne w Person("Joe", "Sixpack")) ;

              // in child:
              opener.addPerso n("Jane", "Fivepack") ;

              This way the Person object is created in the same frame/window that also
              holds its constructor. Maybe that'll make IE happy.


              - Conrad

              Comment

              • SAM

                #8
                Re: How to add array elements to parent window from child window

                Le 10/26/08 2:03 AM, Conrad Lender a écrit :
                On 2008-10-26 02:43, SAM wrote:
                > onsubmit="opene r.tabl[this.indx.value] = [
                > this.val1.value ,
                > this.val2.value
                > ];
                ..
                >works with IE and Fx
                >
                Sure, but it doesn't do what the OP was describing. It just adds an
                array to the array in opener, not a new object. As I said earlier, the
                array isn't the problem.
                object or array what importance ?

                the x element of original mother's array is changed in a new sub-array

                if object is realy absolutly wanted :

                onsubmit="opene r.tabl[this.indx.value] = {
                'name': this.val1.value ,
                'firstname': this.val2.value
                };

                --
                sm

                Comment

                Working...