• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

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
0
Acorn
Asked:
Acorn
  • 3
  • 3
1 Solution
 
EEKCommented:
Pretty similar thing handled here: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20549420.html

"opener" is the keyword you need.

-EEK
0
 
AcornAuthor Commented:
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
0
 
lil_puffballCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
AcornAuthor Commented:
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....

0
 
lil_puffballCommented:
Hmm. Well, why don't you call the function to open UserEditWin from the main page? e.g.

<a href="#" onClick="window.opener.open_third_popup()">

and on the main page:

function open_popup() {
window.open('url.htm','UserEditWin')
}
0
 
AcornAuthor Commented:
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??

0
 
lil_puffballCommented:
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...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now