Best way to fire an event in the opener from a popup

T

TH

Hi there

What's the best way for a popup to cause an event to fire in the
opener? I've got a popup which currently returns a value to the opener
by setting a hidden input in the opener:

window.opener.document.forms[0].myHiddenField.value=returnValue;
window.close();

I then want the opener window to perform some work on the returned
value. The best I've come up with so far is to put a button on the
opener page, try to hide it with css, give it an onclick value which
calls the function I want to run, then have the popup click it:

window.opener.document.forms[0].myHiddenField.value=returnValue;
window.opener.document.forms[0].myHiddenButton.click();
window.close();

Is there any less clunky method than using an invisible button like
this?

Thanks, TH.
 
P

pangea33

TH said:
Hi there

What's the best way for a popup to cause an event to fire in the
opener? I've got a popup which currently returns a value to the opener
by setting a hidden input in the opener:

window.opener.document.forms[0].myHiddenField.value=returnValue;
window.close();

I then want the opener window to perform some work on the returned
value. The best I've come up with so far is to put a button on the
opener page, try to hide it with css, give it an onclick value which
calls the function I want to run, then have the popup click it:

window.opener.document.forms[0].myHiddenField.value=returnValue;
window.opener.document.forms[0].myHiddenButton.click();
window.close();

Is there any less clunky method than using an invisible button like
this?

Thanks, TH.

Just execute the same method that the button does when clicked. For
instance if it calls "fDoStuff()" in the onclick event, just call it
from the child window like this: window.opener.fDoStuff();

*** popTest.php ***
<html>
<head>
<script language="javascript">
function fDoStuff() {
alert(document.forms[0].myHiddenField.value);
}
function fPopIt() {
window.open('popTest2.php', 'mywin');
}
</script>
</head>
<body onload="fPopIt();">
<form>
<input type="hidden" name="myHiddenField" id="myHiddenField">
</form>
<body>
</html>

*** popTest2.php ***
<html>
<head>
<script language="javascript">
function fDoStuff() {
window.opener.document.forms[0].myHiddenField.value='bennie';
window.opener.fDoStuff();
self.close();
}
</script>
</head>
<body onload="fDoStuff();">

<body>
</html>
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top