By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

How do you Notify Parent window after finished with Child?

Frinavale
Expert Mod 5K+
P: 9,731
I've seen this question being asked over and over again and don't know the answer.

Situation:
There's a web browser displaying a list off stuff.
There's a button that lets the end user add a new thing to the list of stuff.
A new web browser is opened to let the end user enter the information about the thing.

Question:
Is there a way to notify the Parent window when the user's finished entering information about the thing so that they can update the list of stuff?

Thanks for any pointers on how to achieve this.

-Frinny
Jan 6 '09 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
You could use a button where onclick you could refer to the parent using window.opener. You could also avoid popup windows by using DHTML.
Jan 6 '09 #2

Frinavale
Expert Mod 5K+
P: 9,731
@acoder
I'll look into window.opener thanks.

@acoder
This is usually what I recommend because it just makes so much more sense in the long run...today I felt like giving people the answer they're actually looking for :)
Jan 6 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
Window.opener works like a dream :)

Thanks again!
Jan 6 '09 #4

acoder
Expert Mod 15k+
P: 16,027
You're welcome :) @Frinavale
I know what you mean. It's a bit like when a client insists on something that's not quite best practice.
Jan 6 '09 #5

Frinavale
Expert Mod 5K+
P: 9,731
There doesn't appear to be a window close event...

Is there a way for the parent to be able to tell when the child window is closed?

Or is there some event, other than a button click, that is fired when a window is closed...so that the parent can be notified?
Mar 10 '09 #6

acoder
Expert Mod 15k+
P: 16,027
You can use the window.closed property.

When a window is closed, on(before)unload should fire, but it also fires when moving/refreshing.
Mar 10 '09 #7

Frinavale
Expert Mod 5K+
P: 9,731
The fact that it's fired when the window is moving is not good.
I tried setting:

Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = myFunctionThatNotifiesTheParentWindow;
However when I clicked the close button in the child window, the parent window was not notified.

<edit>Right, sometimes I'm an idiot, I placed that code in the parent window, not the child! No wonder it wasn't working >>blush<< I wonder if the other stuff I was trying would have worked had it have been placed in the child window...</edit>
Mar 10 '09 #8

acoder
Expert Mod 15k+
P: 16,027
Sorry, by moving, I meant moving back and forward in the browser history or simply visiting a link. Note that this doesn't happen in Opera, though.

How are you trying to notify the parent window? Do you call a function in the parent?
Mar 10 '09 #9

Frinavale
Expert Mod 5K+
P: 9,731
@acoder
That makes more sense....I tried moving the window and wondered why the closed event didn't fire when I moved it..........hehe

@acoder
Yes, I have a function in the parent that is called by the child.

Parent Page (onload the window parent window is given a name):
Expand|Select|Wrap|Line Numbers
  1. function DoStuff() {
  2.     //Does some stuff
  3.  }
Client Page:
Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = CloseEvent;
  2.  
  3. function CloseEvent() {
  4.    if (window.opener && !window.opener.closed) {
  5.       window.opener.DoStuff();
  6.    }
  7. }
It's pretty simple actually...the reason it wasn't working before was because I had placed the window.onbeforeunload code in the wrong place.
Mar 10 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.