[thelist] Popup and opener interaction

Rick den Haan rick.denhaan at gmail.com
Fri Feb 2 09:48:11 CST 2007


We're currently building a live support-application using a centrally 
hosted javascript/php/mysql application. Centrally hosted, so our 
customers need only include three brief lines of javascript into all 
pages on their website they want the support to be available on.

Our application uses a popup-window for the communication. What I'd 
like, is to know when the visitor closes that pop-up. Currently, I'm 
checking whether the window has been closed every second, using this 
relevant portion of our code:

var oCommunication;
var oComCheckInterval;

function beginCommunication()
    oCommunication = window.open(sComUrl, 'SupportCommunication', 
    if (typeof oCommunication == "undefined" || oCommunication == null) 
    if (!oCommunication.opener) oCommunication.opener = self;

    oComCheckInterval = setInterval("checkComClosed()", 1000);

function checkComClosed()
    if (typeof oCommunication == "object" && oCommunication.closed)
       oCommunication = null;
       // message to server -> client closed window

Now, here's the problem:

It is quite possible for the visitor to browse the website (opener) 
while the popup is open. In that case, the oCommunication variable is 
reset, and I've lost track of whether or not the popup is still open. 
I'm reluctant to use onunload in the popup, because that will also be 
called if the user refreshes the popup window. Besides, running a quick 
message to the server indicating the window is about to close doesn't 
always work if the connection is slow (it's cross-domain, so we had to 
come up with something other than an XHR).

I already tried sending a regular signal to opener from the popup, but 
since the opener is the customer's website, and the popup is running on 
our server, some browsers don't allow that, because it's cross-domain.

Now the popup has a name (SupportCommunication). I mean, when I try to 
open another session from the opener, using the same functions, a second 
popup is *not* opened, but the already open one is redirected. Is it 
possible to check for this name somehow? I haven't found anything like 
this on Google.

I've tried these (and variations) but this approach doesn't seem to work:

oCommunication = window.SupportCommunication;
oCommunication = window['SupportCommunication'];
oCommunication = window.frames['SupportCommunication'];
oCommunication = document.SupportCommunication;

Is what I want even possible?

Thanks in advance for any help,


More information about the thelist mailing list