Archive for July 23, 2009

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
‘window.Array’.

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 …

July 23, 2009 at 7:29 pm Leave a comment


Calendar

July 2009
M T W T F S S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Posts by Month

Posts by Category


Follow

Get every new post delivered to your Inbox.