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

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?

irt.org | Knowledge Base | JavaScript | Frame | Q817 [ previous next ]

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?

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>

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.