Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q339 How can I submit a form on a popup window and target the results into the main window and close the popup window at the same time, even if the location of the main page has changed?

You are here: irt.org | FAQ | JavaScript | Window | Q339 [ previous next ]

topFrame.html:

<HTML>
<FRAMESET ROWS="100%,*">
<FRAME SRC="visiblePage.html" NAME="visibleFrame">
<FRAME SRC="hiddenPage.html" NAME="hiddenFrame">
</FRAMESET>
</HTML>

visiblePage.html:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
myPopup = '';

function openPopup(url) {
    myPopup = window.open(url,'popupWindow','width=640,height=480');
    if (!myPopup.opener)
         myPopup.opener = self;
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Open Popup" onClick="openPopup('popupPage.html')">
</FORM>
</BODY>
</HTML>

hiddenPage.html:

<HTML>
<BODY>
<FORM NAME="hiddenForm" ACTION="targetPage.html" TARGET="visibleFrame">
<INPUT TYPE="TEXT" NAME="myTextField">
</FORM>
</BODY>
</HTML>

popupPage.html:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function copyForm() {
    opener.top.hiddenFrame.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
    opener.top.hiddenFrame.document.hiddenForm.submit();
    window.close();
    return false;
}
//--></SCRIPT>
</HEAD>
<BODY onLoad="opener.location.href='nextPage.html'">
<FORM NAME="popupForm" onSubmit="return copyForm()">
<INPUT TYPE="TEXT" NAME="myTextField">
<INPUT TYPE="BUTTON" VALUE="Submit" onClick="copyForm()">
</FORM>
</BODY>
</HTML>

nextPage.html:

<HTML>
<BODY>
<H1>nextPage.html</H1>
</BODY>
</HTML>

targetPage.html:

<HTML>
<BODY>
<H1>targetPage.html</H1>
<SCRIPT LANGUAGE="JavaScript"><!--
document.write('<P>Data passed = ' + location.search);
//--></SCRIPT>
</HTML>

Feedback on 'Q339 How can I submit a form on a popup window and target the results into the main window and close the popup window at the same time, even if the location of the main page has changed?'

©2018 Martin Webb