Determining whether an orphaned child window is still open
Posted on 2007-12-05
Here's a good one for you.
I need a way to determine whether an orphaned popup window is still in existence, after the calling page has reloaded (or changed pages).
Oh, and the solution can't use other popup windows or "background" documents, and cookies are not an option.
What is he talking about?
index1.html creates a popup window called "pop1" using a standard window.open() call. It assignes a reference to this new window in a variable. As long as we stay inside index1.html, we will be able to do stuff to the popup window by referencing the variable we assigned the instance to.
Now, from index1.html, link to index2.html. As humans, we know that pop1 still exists, but index2.html has reloaded and no longer contains the reference to the child window.
Now we can re-establish the connection to the child window from index2.html by trying to open a new popup window with the same name and an empty URL - window.open ("", "pop1"); This is great if the window does indeed exists. We have restablished the connection, and interestingly, pop1 is not reloaded. That works great. Problem is, if pop1 does not, in fact, exist, then we have this stupid popup window that appears. Sure we can close it immediately after, but you still have a really suspect popup that appears and disappears. People will suspect something fishy.
So, how to determine whether pop1 is in existence without getting an annoying popup if it is not? And without using background windows, additional popups or cookies.
Look forward to your (tested!) suggestions.