JScript Event Listener from Child Window - PLEASE HELP!!!

K

keith

Hello,

I have an object on a parent page. I also have a child window spawned
off that parent page. I want the child window to listen for an
"onclick" event on that object and execute some actions when that
happens. The code is as follows:

object on parent page:
<INPUT type="button" value="My Button" name="MyButton"
onclick="doSomething">

listener on child page:
<script language="JScript" event="onclick" for="window.opener.MyButton"alert("Hello World");
</script>

I have tried removing the "onclick" event from the button, i've
verified that referencing the object as "window.opener.MyButton" works.
I've verified that if I place the listener directly on the parent page
it works. PLEASE HELP!!!! What am I missing???
 
C

Csaba Gabor

I had a similar situation where I had a CSS expression in
one frame that wanted to call a function in another. If
I remember right (and I might not), then in all the variants
I tried, the expression didn't like calling across frames.

But it had no problem with a helper function doing it.

So what I would try is to place a reference to the opened
window within the opener (which you have if you used
window.open, or any other normal method). and then
doSomething is in a SCRIPT tag in the parent reading something
like:

function doSomething() {
window.openedWindow.doSomethingInChild();
}


In the child window:
<script type="text/javascript">
function doSomethingInChild() {
alert("Hello World");
}
</script>

and if that variant doesn't work, then try the call like this:
window.openedWindow.setTimeout(window.openedWindow.doSomethingInChild,10);


Good luck,
Csaba Gabor from Vienna
 
R

RobB

keith said:
Hello,

I have an object on a parent page. I also have a child window spawned
off that parent page. I want the child window to listen for an
"onclick" event on that object and execute some actions when that
happens. The code is as follows:

object on parent page:
<INPUT type="button" value="My Button" name="MyButton"
onclick="doSomething">

listener on child page:
<script language="JScript" event="onclick" for="window.opener.MyButton"
alert("Hello World");
</script>

I have tried removing the "onclick" event from the button, i've
verified that referencing the object as "window.opener.MyButton" works.
I've verified that if I place the listener directly on the parent page
it works. PLEASE HELP!!!! What am I missing???

Appears to be some sort of scoping issue, maybe similar to MSIE's
refusal to allow cross-window scripting of some host objects. This
works:

in opener....

<script language="JScript" event="onclick" for="MyButton">

if (foo && !foo.closed) foo.xw();

</script>

....where 'foo' is the global variable you returned window.open() to
('handle').

in pop-up....

<script language="JScript">

function xw()
{
alert("Hello World");
}

</script>

Why use these proprietary attributes at all? Plenty of issues with DOM
event handling to keep you busy... #:=)
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top