By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

2nd call from child window to parent fails

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

"Bill Borg" wrote:
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.