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

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

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

Dec 4 '06 #1
Share this Question
Share on Google+
2 Replies


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

Dec 4 '06 #2

P: n/a
TH
Cheers pangea!

Jan 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.