from my first window (I'll refer to it as window 1) I'm opening a second window (window 2) using
var w = window.open("", "");
From within window 2 I'm referencing and manipulating an array defined in window 1 using code like
window.opener.object2[0].drivedistance = driveDistance;
This code works fine. However, before displaying the results of this array in window 2 I need to sort it. My attempt at sorting:
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 seems to work fine.
When I step through the code I can see that it's executing the code in compareDriving. No exceptions are being thrown. However, after it gets done calling compareDriving the array is not sorted. I don't know if maybe this is some kind of a security issue because the array I'm sorting exists in window 1, but my javascript is in window 2? Any ideas on why this sort code isn't working would be much appreciated.
Based on comments I put together a jsfiddle of the issue that seems to demonstate it well. To be clear on the final solution, I need page 1 to be the repository of the collection, but I need page 2 to initiage the logic that causes the collection on page 1 to be sorted.
Bizarre. After playing with this some more it looks like I may be able to accomplish what I want by passing the sort function a handler that exists on page 1 instead of page 2. But when I run the function remotely on page 2 it sorts in the inverse order as when I run it from page 1. I can probably play with this to get it to work, but would still appreciate any suggestions on best practices. Here's my latest fiddle of my findings.
Keep in mind that you'll need to enable popups to test any of these as I'm working with popup functionality.
Edit. I'm finding that cross-browser results are very spotty on the last jsfiddle. A buddy of mine tried it in chrome and it worked for him. I tried it in my chrome and the results aren't sorted. IE sorts in reverse. I haven't gotten firefox to work at all. Any help on a method to accomplish cross window sorting that is cross-browser compatible is what I think I'm really after here. Thank you for any and all answers.