2nd call from child window to parent fails

G

Guest

Hello all,

Simple chat app, where the site owner has a master window with all requests
for chat, status of each room, etc., and child windows for each separate chat
in which the owner is engaged. When the owner closes one of his child
windows, I want to update the master window.

I understand "reasonably" well how to go about this. The master window
launches the children, and maintains an associative array to keep track of
each one. When a child closes, I want it to tell the master to remove it from
its list (this will happen on periodic polling from the master as well). So,
child.unload calls window.opener.removeMe.

The problem is that the first time a child calls removeMe on the parent, it
seems to work, but on the second I get "object doesn't support this
property...". I've stripped everything down to the barest html as follows,
where as you'll see the parentPage fires up a childPage, and the childPage
has a button to run a function in the parent. First time I click the button I
get expected behavior, but the second time I get the same "object doesn't
support..." error, even though window.opener still appears valid.

*testParent.html*
<html>
<head>
<script>
function startRequest() {
w = window.open('testChild.html', 'myChild');
}
function childCall() {
document.write('Child did this...');
}
</script>
</head>
<body onload="startRequest();">
</body>
</html>

* testChild.html *
<html>
<head>
<script>
function updateParent() {
window.opener.childCall();
}
</script>
</head>
<body>
<form>
<input type=button value="Update Parent" onclick="updateParent();">
</form>
</body>
</html>

I think I'm missing something fundamental re scope and/or lifetime, but
don't see it. Any tips are greatly appreciated.

Thanks,

Bill
 
G

Guest

P.S. I now see the problem, but still don't understand what's happening. When
I call the parent function 'childCall()', the document.write in there is
overwriting the parent window with the child window, including location, etc.
If instead of doing document.write I do, say, divMyParentLabel='..whatever'
I'm good to go. Might be implicit open/close on the document object, or maybe
I'm not understanding the scope of the parent/child function calls and which
'document' is in play. Any additional thoughts are appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top