You're right, this isn't a Perl question. I'm not a JavaScript genius, but you might consider using the other window's onUnload event to trigger your logic in the first window. I'm not sure you can easily write "wait until this other window is closed" in JavaScript, but you can write "when I close, call this function in this other window," provided you're in the same security context.