Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference to a child window

Status
Not open for further replies.

salils

Programmer
Mar 11, 2002
12
0
0
US
Hello,
My problem is that I am opening a child window from a parent window. Now the parent window gets replaced by some other page and I lose the reference to the child window. If the user again tries to open the child window from the same parent window I want to check that the child window is not already open and prevent the child from opening again. But since the parent window would be refreshed by some other page I lose the reference to the child window. How do I solve this problem.
 
Hi, just check if the window is open before open again. If already open just set focus to it.

if (window.mywind) {
mywind,focus();
}
else {
var mywind=window.open("xxx.htm","","locationbar=0,menubar=0, ...");
}

Sergio M Netto.
 
Hello smnetto,
but if the parent window page is replaced by a new page then the var mywind will be lost. For eg. if Parent.html opens Child.html and Parent.html is replaced by Replace.html. When Parent.html is loaded again then then reference to the Child window will be lost and hence window.mywind will be false. How do I keep a reference to this window even when the parent window is replaced by some other page.
 
Here is how you can reference child window and check if it's still opened or already closed:

if (mywind.closed)
   ... // open it using window.open()
else
... // don't open it again


Try it.
By the way, you can also detect if parent window was closed or not using this:
if (window.opener.closed)

 
salils, sorry, now i understand what u want. Every reference to windows opened by window.open method can be only referenced by the object id, the var in this case. If the parent window (opener) get a refresh, javascript cant reference this object (window). The solution can be asp with javascript, passing request querystrings, like session, to reference the objects that you create. Maybe exist another ways to do this, but in this moment i could not think another way.

sorry about my english, im from brazil...

sergio m. netto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top