[thelist] Popup and opener interaction

Rick den Haan rick.denhaan at gmail.com
Fri Feb 2 16:54:12 CST 2007

Anthony Baratta wrote:
> Do you want the Customer's Site to be notified of the Popup closing or your site to be notified?
I want our site to be notified.
> Why is tracking the closing of the Popup important?
The moderator (logged in at our server) needs to know when the visitor 
(on the customer's server) has closed his window. No point typing 
messages if they're not getting through :)
> What I would try is using the onunload funciton, run an AJAX script that communicates with your server about the closure of the popup. If you combine that with an onload AJAX function, you should have the start and end time for each popup. A refesh should be considered a new popup instance, so that should fit the scenario.
I've tried that. However, using onunload, sometimes the communication 
with the server is incomplete by the time the popup window actually closes.

Kasimir-k wrote:
> I had a bit similar situation and ended up not calling the pop-up from 
> our server, but using document.write in the script the clients include 
> on their pages. This way the pop-up can communicate to the opener.
I hadn't considered that one yet. But now that I have, the javascript is 
already growing rather large. I'd rather not put all the functions 
necessary for the actual chatsessions and all the output to fill the 
popup in the customer's site as well, because that would significantly 
increase the size of the JS file.

What I'm currently considering is a different option. Anthony's line 
about having the start and end time for each popup strummed a chord. In 
the popup window, there is currently a script that runs every 500 ms and 
checks for new messages. I could probably append to this script to also 
update a timestamp in the database. That would always be current, as 
long as the popup window is open. Reloading the popup wouldn't have any 
effect in that case. I could then check on the stored timestamp, and 
assume the visitor has closed the window if it is older than..... 5 or 
10 seconds ago.

But, although this would solve my particular problem for this current 
project, it doesn't answer the fundamental question. Is it possible to 
retrieve a child window, if the opener no longer knows about it? It 
might be possible to try to window.open() a javascript url into a popup 
with the same name. In my case:

At first:
window.open(sComUrl, 'SupportCommunication', sComProps);

Then, after the opener has lost it:
window.open('javascript:if (typeof someVariable == "undefined") { 
opener.oCommunication = null; self.close(); } else { 
opener.oCommunication = self; }', 'SupportCommunication', sComProps);

Where someVariable would be something that's supposed to be in the popup 
window. Or, come to think of it,  "if (history.length > 0)" might work.

This is just brainstorming a bit here, I'm too lazy to actually work on 
it right at the moment, but what do you think?


More information about the thelist mailing list