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

Q906 How can I update the contents of a popup window when pressing a form button in the popup window, and using the opener window to hold all the necessary code?

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

IIRC there are sometimes errors when invoking a function in a parent window to overwrite the content of the poupup window, before control is then passed back to the popup. The following _should_ get around this problem:

<script language="JavaScript"><!--
var myWindow = null;
var output = '';

function openWindow() {
    myWindow = window.open('about:blank','windowName','width=300,height=300');
    if (!myWindow.opener)
        myWindow.opener = self;
    setTimeout('outputContent(writeWindow1())',100);
}

function writeWindow1() {
    output = '';
    output += '<form>';
    output += '<input type="button" value="Click Me #1" onClick="document.open();document.write(opener.parent.writeWindow2());document.close()">';
    output += '<\/form>';
    return output;
}

function writeWindow2() {
    output = '';
    output += '<form>';
    output += '<input type="button" value="Click Me #2" onClick="document.open();document.write(opener.parent.writeWindow1());document.close()">';
    output += '<\/form>';
    return output;
}

function outputContent(output) {
    myWindow.document.open();
    myWindow.document.write(output);
    myWindow.document.close();
}

openWindow();
outputContent();
//--></script>

©2018 Martin Webb