Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access a window variable from a popup window?

I already lost some hours trying to figure out how to solve a javascript problem. I have a JS function that opens a popup window:

function openSearchWindow(searchType, targetIdField, targetDescField)

and I set 2 properties to this new window:

var win = window.open(searchPage, searchType + "search", style);
win.targetIdField = targetIdField;
win.targetDescField = targetDescField;

Until here, everything works perfectly. In my popup window, however, I need to access these two variables I set previously: win.targetIdField and win.targetDescField

How can I access them? I tried almost everything.

EDIT - In time,

In the popup window I have a search engine actually. When user clicks in a result, there is a JS function that gets the ID and DESCRIPTION of the selected item and passes it back to the "opener" window, placing them in the targetIdField and targetDescField, respectively.

EDIT (2)

Once the search is performed in the popup (through a servlet) the popup's URL changes, but it's always within the same domain.

Thanks in advance.

Lucas.

like image 377
LucasM Avatar asked Oct 28 '25 06:10

LucasM


1 Answers

Have you tried accessing them through window.targetIdField? If thait does not work, you could bind the 2 properties on the parent window (using window.targetIdField instead of win.targetIdField) and then access those from your opened window using window.opener.targetFieldid.

like image 123
Thor Jacobsen Avatar answered Oct 29 '25 19:10

Thor Jacobsen