Web Analytics Made Easy -
StatCounter child window controlling parent not working - CodingForum

Announcement

Collapse
No announcement yet.

child window controlling parent not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • child window controlling parent not working

    Hi, I would like to have the child window (which was created by a link in the parent window) be able to change the content in the parent window.

    The code I'm using works fine except when the child window is in a frameset.

    Window 1: parent

    <head>

    <script type="text/javascript" language="javascript">
    function showRemoteexample() {

    var windowprops = "toolbar=yes,location=0,directories=0,status=1, " +
    "menubar=0,scrollbars=1,resizable=yes,width=600,height=650,top=0,left=0";

    OpenWindow = window.open("remotes_B.html", "remoteexample", windowprops);
    OpenWindow.focus()
    };
    </script>

    </head>

    <body>
    <a href="#" onClick="showRemoteexample();">Open remote window</a>
    </body>






    Window 2: child (is a 3 frame frameset and the code below is in the middle frameset)


    <head>

    <!-- Target Main AST -->
    <script>
    function targetAST(url){
    window.opener.location=url
    }
    </script>

    </head>


    <body>
    <a href="#" onClick="targetAST('http://www.cibc.com');">Clicking this link will change Window 1</a>
    </body>


    I'm completely stumped.

    Thanks.

  • #2
    After you create the new window, set the window's opener value to the current window.

    Code:
    OpenWindow = window.open("remotes_B.html", "remoteexample", windowprops);
    OpenWindow.opener = window.top; //added this line.
    OpenWindow.focus()
    Since the function is inside a frame inside a window, use window.top.opener or window.parent.opener
    Code:
    <script>
    function targetAST(url){
    window.top.opener.location=url; //added a .top to get access to the top most window.
    }
    </script>

    Comment

    Working...
    X