from my first window (I will call it as window 1) I open the second window (window 2) using
var w = window.open("", "");
From window 2, I reference and manipulate the array defined in window 1 using code like
window.opener.object2[0].drivedistance = driveDistance;
This code is working fine. However, before displaying the results of this array in window 2, I need to sort it. My sorting attempt:
window.opener.objects2.sort(compareFunc) function compareFunc(a, b){ return (a.drivedistance - b.drivedistance) }
If I use the same method in jsfiddle without calling from a remote window, it works fine.
http://jsfiddle.net/98Q4D/10/
When I look at the code, I see that it is executing the code in compareDriving. No exceptions are thrown. However, after this is done, call compareDriving, the array is not sorted. I donβt know, maybe this is some kind of security problem, because the array that I am sorting exists in window 1, but my javascript is in window 2? Any ideas on why this sorting code doesn't work would be greatly appreciated.
Based on the comments, I put together a jsfiddle problem that seems to demonstrate it well. To understand the final solution, I need page 1 to be the collection repository, but I need page 2 to initialize the logic, which causes the assembly on page 1 to sort.
http://jsfiddle.net/mexP6/26/
Bizarre After playing with this a little more, it looks like I can do what I want by passing the sort function to the handler that exists on page 1, and not on page 2. But when I run the function remotely on page 2, it is sorted in reverse order as when I start it from page 1. I can probably play around with this to get it working, but I will still appreciate any suggestions for best practices. Here is my last scenario of my findings.
http://jsfiddle.net/mexP6/23/
Keep in mind that you need to enable pop-ups to check them when I work with pop-up functions.
Change I find that cross-browser results are very spotty on the latest jsfiddle. My buddy tried it in chrome and it worked for him. I tried this in my chrome and the results are not sorted. IE is sorted in reverse order. I don't have firefox to work at all. Any help on cross-window sorting method compatible with cross-browser is what I think I'm really here. Thanks for any answers.