tags:

views:

170

answers:

2

Hi,

I'm actually coding a case where a child popup window transfer data to parent window as:

var childArrayData = new Array();
childArrayData[0] = 'Data text1';
childArrayData[1] = 'Data text2';
childArrayData[2] = 'Data text3';
window.opener.parentVariable = childArrayData;

I got an error which was solved like:

var childArrayData = new window.opener.Array();     <-----
childArrayData[0] = 'Data text1';
childArrayData[1] = 'Data text2';
childArrayData[2] = 'Data text3';
window.opener.parentVariable = childArrayData;

Why is Array class different between two different windows? Does it relate to namespacing? May you refer to any article about the answer?

Thanks in advance.

Best,

Esteve

A: 

why are you even using the Array constructor?
try using the [ ] notation instead

which browser are you using btw? are the two frames on the same domain?

Ken Egozi
Hi Ken,in fact, the problem is not only in Array class but in any class "shared" between parent and child windows.All tests where done on Firefox.Sorry to ask you, but what do you refer to the domain?Thanks Ken for your answer ;)Esteve
Esteve Camps
+1  A: 

It's a known issue. Read this post on comp.lang.javascript written by Douglas Crockford.

When you say Array, you are talking about window.Array. window is the browser's context object, and you get one per page (or frame). All of the arrays created within a context will have their constructor property set to window.Array.

An array created in a different context has a different window.Array, so your test

myArray instanceof Array

fails. The ECMAScript standard does not discuss multiple contexts, even though virtually all implementations support them. The ECMAScript standard also fails to provide a reliable technique for testing the type of arrays. The obvious thing would have been

Ionuț G. Stan
Thanks a lot Ionut.
Esteve Camps
You welcome, Esteve.
Ionuț G. Stan