aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Referring to a child window? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Referring to a child window?" Watch "Referring to a child window?" New topic
Author

Referring to a child window?

Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
I have an HTML page where user needs to login to view the page.

Then there's a link in the HTML page.
When user clicks the link, it opens a pop-up box.

How do I close this pop-up box when I sign out from the parent page?
Is there anyway to do this?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The window.open function returns a handle to the newly created window.
You can assign that to a var and use that to refer to it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Thank you. It's working great.
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Actually, there's one problem.

I have external javascript called myjavascript.js




Then when i logout in the parent page, let's call it A.html, I do this below:



The code works fine in this case:
1.) Open A.html
2.) Click a link in A.html to open "mywindow"
3.) Sign out, then I see that 'mywindow' is also closed when I click "Sign out"

But not in this case:
1.) Open A.html
2.) Click a link in A.html to open "mywindow"
3.) Reload A.html
4.) Sign out, then I see that "mywindow" is not closed when I click "Sign out"

I think it's because in step. #3, the mywindow variable is initialized to "undefined" again. How do I prevent this from happening?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

You don't. Once the parent window is unloaded, any reference to the child is lost.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Once the page is refresh, navigated away form, posted back, etc all of the JavaScript variables are killed. There is no way to keep this from happening so the child window will be orphaned.

You can close the window with onbeforeunload or onunload and reopen it when the page is loaded again. Other than that, you are out of luck.

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Referring to a child window?