Link to home
Start Free TrialLog in
Avatar of Acorn
Acorn

asked on

window.opener from SECONDARY Popup

Folks,
  I have a Main window (MainWin) that calls window.open() to open up a child popup window (UserInfoWin). This works fine. That Popup window spawns a SECONDARY popup (UserEditWin) via another call to window.open() AND THEN UserInfoWin closes itself using self.close();. The user then works with the data in UserEditWin, and when they click a link, I would like the following to happen:
 
  I would like UserEditWin to be able set a value in a form (myForm) in the MainWin, and then submit that form. If it was UserInfoWin that was setting the values then I could just call window.opener.myForm.submit(), but it is not the direct opener of the window (UserInfoWin has closed).
 
  I have tried referring to this window by name, AKA:
  <A HREF='#' ONCLICK='Javascript:MainWin.document.myForm.ok.value=1;MainWin.document.myForm.submit();return true;'>Click here to submit</A>
  But apparently this MainWin is not referancable globally because I get a "Not Defined" error.

  Any ideas on how to get this working? How can I refer to windows from other (unrelated) windows?

thanks in advance
Avatar of EEK
EEK

Pretty similar thing handled here: https://www.experts-exchange.com/questions/20549420/Changing-URL-of-window-from-a-POPUP.html

"opener" is the keyword you need.

-EEK
Avatar of Acorn

ASKER

EEK,
  I'm not sure you read all of my question. The opener has been closed. Again, it's three windows, I want to control the MainWin from a SECONDARY popup, not the FIRST popup.

1) MainWin->User Click->Popup UserInfoWin
2) UserInfoWin->Click->Popup UserEditWin;Close UserInfoWin
3) UserEditWin->Click->Set Value on form on Mainwin;Submit Form on MainWin.

Thanks
EEK,
These 2 are completely different questions, please read the question more carefully.

Acorn,
Are you sure you gave the main window the name 'MainWin'?

If it doesn't work, try having a hidden form on the first popup, passing the variable to the hidden form, then having the info on the hidden form passed the the main window.
Avatar of Acorn

ASKER

lil_puffball,
  I am pretty sure I named the main window correctly. To test it I added an ONCLICK='alert(window.name);' to a link on the MainWin page and got "MainWin" in the alert box.

  I'd try passing the variables back and forth, but I'm not ALWAYS guaranteed that the user will go from MainWin->UserInfoWin->UserEditWin. They might go directly from MainWin->UserEditWin based on where they are coming from in the site. (Sorry to throw out another wrench!).

  I'm a little confused as to why I cannot refer to MainWin directly by name. Doesn't seem natural to me. Is this normal? IE 5.5....

ASKER CERTIFIED SOLUTION
Avatar of lil_puffball
lil_puffball
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Acorn

ASKER

Ack!! I think you meant on the main page:

function open_third_popup() {
...

But I get your drift. That is very doable. Not elegant as I'd like, but it sure gets the job done.

Any idea why I couldn't refer to this window name directly? Are you not allowed to refer to window names like that? MainWin isn't a reserved name or something is it??

Acorn,
so sorry, I did do a typo! :)
But no, I'm sure MainWin isn't a reserved word. Three things tell me so--Usually reserved words contain only lowercase letters, second of all they are usually only 1 word (e.g. window, document, top, etc.) and third they usually contain full words (so it'd probably be MainWindow rather than Win.) I'm not too sure why you can't reference windows that way. Perhaps when you open more than one window they don't have a 'connection' anymore, so they can't reference each other, much like you can't reference any other webpages open on the user's browser unless you directly opened them. The reason for this may be:
-What if you opened a window for the user that you didn't know what would be on it? And let's say your window is called MainWin. But what if that opened page is also called MainWin? (For example if the code said self.name='MainWin') And then from that page the user opened a third popup that made a reference to MainWin? How would the computer know which window it referred to??? Anyway, just my speculations...