using Array methods over frame borders?

The other day i tried to join a javascript Array to pass it over to another page within my application.
I stumbled upon the error message in IE7

Unexpected call to method or property access.

Ok, it must have got something to do with a method that is used on an array:

link += "&elements=" + parent.frames[1].arrElements.join("|");

After consulting Google i found several pages, and this is the most targeting link: myArray instanceof Array fails after passing to a different page.
Douglas Crockford states:

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

So i assume this to be the reason why my call .join() fails.

So what would be a workaround?

I had to create a local array and copy all the elements from the original array into my local array and join this one to the link:

var joinHelper = "";
for (var i = 0, j = arrElements.length; i < j; i++) {
joinHelper += arrElements[i];
if (i < j) {
joinHelper += "|";
link += "&elements=" + joinHelper; // instead of parent.frames[1].arrElements.join("|");

… time to call it a day …

This entry was posted in javascript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s