Javascript pass data from child window to parent window, IE error?

I got a popup that returns data to my parents. Using window.opener.document.data = data_from_popup;

This work well in FF, but in IE (6/7) you can access the data while the popup is displayed. When I close the popup, it looks like the data is collecting garbage.

I tried using the clone () function for the data received from the popup:

 window.opener.add_data(data_from_popup); 

and in the parent:

 function add_data(data_from_popup) { data = clone(data_from_popup); } 

This works, but under certain conditions, the clone() function seems to solve endlessly.

Have you ever experienced the same thing, and is there a way to prevent this without using the clone function?

+6
javascript garbage-collection internet-explorer popup
source share
2 answers

Not sure what exactly you are experiencing, but I successfully saved the opening data from a child popup on a regular basis in IE (6.7 and 8) in development and production applications.

Do you have a url or some other source code that you can provide?

in the corresponding note ... you are not trying to determine the type of object on the opener ... are you from the pop-up window? - There are some known IE errors in this area.

Update:

Here is a quick example ...

 <!--main window--> <script> function getThing(id){ url = 'http://mysite.com/...whatever...'; features = 'locationbar=X,menubar=Y...'; window['popup4'+id] = open(url, 'someNameWithoutSpaces', features); } function popupCallback(data){ alert('I got data back! ' + data); document.getElementById('someID').innerHTML = '<b>' + data.label + ' (' + data.id + ')</b>'; //close the popup (now that we have/are done with the data) window['popup4someID'].close(); } </script> <div id="someID">{Nothing Selected Yet}</div> <input type="button" value="Pick One" onclick="getThing('someID');"/> <!--popup window--> <script> function saveSelection(){ //acquire data however you want/need var selData = {}; selData.id = 123456; selData.label = 'iPod Touch (Jeff Atwood Edition)'; //call callback on opener window.opener.popupCallback(selData); } </script> 

Update 2

When testing, it appears that in IE7 IE8 (but not IE6) after closing the pop-up window, any link data is lost (links do not capture the snapshot), so if you need data after the pop-up closes, you will need to clone it.

I thought that if data can be wrapped in an array, cloning is a piece of cake. Just call .slice () to copy it , but ... this does not work. !

I think you will need to save the values ​​you need (either to create the elements, or for the DOM), since IE does not look like you can use them after closing the popup. :-(

+6
source share

The way I finally did this is json encoding a complex object that I wanted to pass to the parent in a popup. The data passed back is a simple string and can be copied without problems. On the parent side, a json encoded string is evaluated by a Javascript object.

+2
source share

All Articles