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

Q817 How can I access a variable in the parent frameset of a window that opened a popup window, from within a frame in the popup window?

You are here: irt.org | FAQ | JavaScript | Frame | Q817 [ previous next ]

First you need to navigate to the top frameset in the popup window. Then you have to refer to the opener window, and then the top frameset within the opener window:

If the main window index1.htm contains:

<SCRIPT LANGUAGE="JavaScript"><!--
var myVar = 'Hello World';
//--></SCRIPT>

<FRAMESET COLS="50%,*">
<FRAME SRC="frame0.htm">
<FRAME SRC="frame1.htm">
</FRAMESET>

and then in frame0.htm you had a link that opened another window:

<SCRIPT LANGUAGE="JavaScript"><!--
function myOpen(url) {
    myWindowHandle = window.open(url,'windowName','width=100,height=100');
    if (!myWindowHandle.opener)
        myWindowHandle.opener = self;
}
//--></SCRIPT>

<A HREF="javascript:myOpen('index2.htm')">Open window</A>

and then in index2.htm:

<FRAMESET COLS="50%,*">
<FRAME SRC="frame2.htm">
<FRAME SRC="frame3.htm">
</FRAMESET>

Then from frame2.htm or frame3.htm to access the myVar variable you would need to use:

<SCRIPT LANGUAGE="JavaScript"><!--
alert(top.opener.top.variableName);
//--></SCRIPT>

©2018 Martin Webb