SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.opener not working with frames, simple example: (all code provided)

    Okay, I have a frameset called index.htm:
    PHP Code:
    <html>

    <
    head>
    <
    title></title>
    </
    head>

    <
    frameset cols="340,67%">
        <
    frame name="left" scrolling="no" src="testopener.htm" marginwidth="0" marginheight="0" noresize>
        <
    frame name="right" scrolling="no" noresize src="dummy.htm">
        <
    noframes>
        <
    body>

        <
    p>This page uses framesbut your browser doesn't support them.</p>

        </body>
        </noframes>
    </frameset>
    </html> 
    In this frameset, testopener.htm is about as simple as you can get, it opens a new window in the right frame when it finishes loading:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Parent</title>
    <
    script language="JavaScript">
        
    window.onload = function() {
            
    window.open("testopened.htm","right");
        }
    </script>
    </head>
    <body>
    <h1>This is the opener/parent window</h1>
    </body>
    </html> 
    the html it opens just has an alert to check the value of window.opener.
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Child</title>
    <
    script language="JavaScript">
        
    window.onload = function() {
            
    alert(window.opener);
        }
    </script>
    </head>
    <body>
    <h1>This is the opened/child window</h1>
    </body>
    </html> 
    The alert window displays 'undefined'.

    If I remove the index.htm and directly open up 'testopener.htm' in a browser, then the 'testopened.htm' opens in a new window and displays '[object]' like you would expect.

    Is there a way for my 'testopened' file to get the window that opened it? Even if I got to the index.htm object window I would be okay.

    My actual page I am doing this testing for has a problem where users using the back arrow extensively combined with rapid link clicking will eventually get a window targeted for "right" to open up in a new window. I don't know why this happens, but I would like to know that my javascript being opened in 'right' can always find the window that opened it (that window has a flash object and my javascript has to be able to find it in the DOM so it can run scripts and communicate with the actionscript in the flash).

    Any help would be appreciated!

    I know frames are the devil, but this site is 1000+ pages and I just inherited it, there is also NO sever side scripting avaialble to me, so things like includes are not available to replace the frames, plust reloading AS messes up it's state and the variables, etc...

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A frame isn't a window and window.opener points to the page that opened the current window. A frame can simply reference other frames by their name or can reference its parent as parent.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, thank you for the clarification!

    I can then cover both bases in my actual code and find the flash object as so:
    PHP Code:
    if (top._menu == undefined){
        
    flash window.opener.document.getElementById("flashObject");
    } else {
        
    flash top._menu.document.getElementById("flashObject");

    edit: code above is working great in both cases.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •