Using javascript objects passed from closed popup
By Anatoly Mironov
It is not a rocket science to pass objects from child window (popup) to main window. The problem I encountered today was IE and passing complex objects. So it is just an IE issue as far as I know. The problem occurs when you pass some object (not a simple String or Number) to main window:
window.opener.takeAnObjectFromChild = {
title: "Should even be available when I close the child"
};
and you then close the child window, next time the main window tries to access the passed object:
console.log(takeAnObjectFromChild);
you’ll get
The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.
Sometimes you can get this error:
Can’t execute code from a freed script
Weird. I saw a solution which “serializes” the object before passing to the main window. But for complex object it would be more headache actually. A better solution is actually to deep clone the object in the main window before closing the popup. If jQuery is there, just run jQuery.extend, like John Resig said :):
window.myClonedObject = jQuery.extend(true, {}, window.takeAnObjectFromChild);
Comments from Wordpress.com
Vonnie Levitz - Jul 6, 2012
I had this content saved a while ago but my notebook crashed. I have since gotten a new one and it took me a while to come across this! I also really like the design though. cerkiner.tk