Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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?

irt.org | Knowledge Base | JavaScript | Window | Q906 [ previous next ]

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?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.