By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

How to add array elements to parent window from child window

P: n/a
I have parent.htm and child.htm
================================================== ===============
In parent.htm we have:

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

================================================== ===============
In child.htm I want to add new elements to parentarray, like
opener.parentarray[6] = .......
Oct 25 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 2008-10-25 02:17, ma**********@juno.com wrote:
In parent.htm we have:
var parentarray = new Array(5)
window.open("child.htm",.....)
In child.htm I want to add new elements to parentarray, like
opener.parentarray[6] = .......
And your problem is...?
- Conrad
Oct 25 '08 #2

P: n/a
Actually here is a more accurate desc of the prob:

parent.htm:

function parentarrayobject(last,first)
{
this.last = last
this.first = first
}
var parentarray = new Array()
parentarray[0] = new parentarrayobject("sixpack","joe") // this works
ok
window.open("child.htm",.....)
================================================== ===============
child.htm:
//--the alert works, pops up with "object"
alert(typeof(opener.parentarrayobject))
//--the next statement chokes... "Invalid procedure call or
argument"
opener.parentarray[1] = new
opener.parentarrayobject("fivepack","jane")
================================================== ===============
The problem is when trying to create parentarray[1] in child.htm it
keeps giving "Invalid procedure call or argument"
Oct 25 '08 #3

P: n/a
On 2008-10-25 23:10, ma**********@juno.com wrote:
Actually here is a more accurate desc of the prob:
...
child.htm:
//--the alert works, pops up with "object"
alert(typeof(opener.parentarrayobject))
//--the next statement chokes... "Invalid procedure call or
argument"
opener.parentarray[1] = new
opener.parentarrayobject("fivepack","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.parentarrayobject()". 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 parentarrayobject created there.
- Conrad
Oct 25 '08 #4

P: n/a
SAM
Le 10/25/08 2:17 AM, ma**********@juno.com a écrit :
I have parent.htm and child.htm
================================================== ===============
In parent.htm we have:

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

================================================== ===============
In child.htm I want to add new elements to parentarray, like
opener.parentarray[6] = .......

And ?

That doesn't work ?

That would have to.

--
sm
Oct 26 '08 #5

P: n/a
SAM
Le 10/25/08 11:10 PM, ma**********@juno.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.htm');">daughter</button>
<button onclick="alert(tabl)">voir </button>
child.htm :

<body>
<h1>children</h1>
<form action="#"
onsubmit="opener.tabl.push(this.elemt.value); return false;">
element to add : <input type="text" name="elemt">
<input type="submit" value="add">
</form>
<form action="#"
onsubmit="opener.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)">see the opener's array </button>
</body>
works with IE and Fx
--
sm
Oct 26 '08 #6

P: n/a
On 2008-10-26 02:43, SAM wrote:
onsubmit="opener.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(new Person(first, last));
}
var persons = [];
persons.push(new Person("Joe", "Sixpack"));

// in child:
opener.addPerson("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
Oct 26 '08 #7

P: n/a
SAM
Le 10/26/08 2:03 AM, Conrad Lender a écrit :
On 2008-10-26 02:43, SAM wrote:
> onsubmit="opener.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="opener.tabl[this.indx.value] = {
'name': this.val1.value,
'firstname': this.val2.value
};

--
sm
Oct 26 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.