Javascript, opener, parent link problem-VBForums
Results 1 to 3 of 3

Thread: Javascript, opener, parent link problem

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,494

    Resolved Javascript, opener, parent link problem

    Hi all.

    I have 3 pages:

    Page 1, the main browser window page of the site
    Page 2, a content page that resides in an <IFRAME> on Page 1 (sometimes)
    Page 3, a content page that opens in a pop-up window from Page 1 and from Page2

    There are links on page3 (popup) that are for the main browser window. SInce sometimes that window's opener is the main window and sometimes the <IFRAME>, I pass a parameter to the popup to tell it who opened it:
    ?Level=1 (if the IFRAME opened it, no parameter if the main window opened it)

    Then there are links in the popup window for the main window (as I've stated already). I handle these links through Javascript:

    var tLevel = Number("<%=tLevel%>") //request("level")
    if (tLevel == 1)
    {window.opener.parent.location.href = "../cand.asp?p=6&chamm=3&by=1"}
    else
    {window.opener.location.href = "../cand.asp?p=6&chamm=3&by=1"};

    So, usually, if the main page opened the popup, the link on the popup will go to the main page
    if the Iframe opened the popup, the link on the popup will go to the iframe's parent, the main page.

    This usually works okay. But I didn't think of one thing.
    If I open the popup window and then navigate the main window off to a different page, that does not contain this IFRAME, the links on the popup no longer function. This is not the case if the popup is launched from the main window links. No matter where I navigate to, the window.opener can still be accessed. It is only when the popup is launched from the IFRAME that the problem can happen.

    So, I need a failsafe in this case. How can the popup page reference the window.opener.parent when the window.opener is gone?

    By the way, the behavior on this is that the main window will show in the status bar "opening page....." and the progress bar will run out from 0 to 100 and then disappear, but the window will not change location.

    Thanks for any suggestions.
    Wengang
    Last edited by wengang; Jul 3rd, 2005 at 09:50 PM.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,494

    Re: Javascript, opener, parent link problem

    hmmm.
    and the problem goes deeper than that.
    When the popup is opened the first time, that window is assigned a name, so that only one such popup can be open at a time.
    When the popup is first opened, the links to opener and opener.parent work.
    But if I go to the opener and click the popup again from a different link (it is a content link, changes info based on which link is clicked), that too causes the popup links back to opener and opener.parent to stop working.

    It would seem that instead of the IF ELSE / parameter method, I should find a way to pass a reference to the popup for that browser window, so that I can reference it from the popup when changing its location.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,494

    Re: Javascript, opener, parent link problem

    OK.
    having trouble getting answers in the ASP/VBScript forum lately.
    Maybe everybody is on vacation.

    Well, here is the answer.

    The main browser window that opens when the user clicks into the site has to be named for reference.
    So add a small JS at the bottom of the page:
    <script language="javascript">
    window.name="CAND";
    </script>

    Then no more parameters or IF ELSE, no more window.opener or window.parent or anything else.
    In the Javascript link on the popup:
    wCAND = window.open("../cand.asp?p=6&chamm=3&by=1", "CAND");
    window.blur();
    wCAND.Focus;

    That will make the main browser window take the link no matter what it currently contains. And if the user has opened the popup and then closed the main browser window, it will open a new window for the link.

    Ideal solution, much less messy.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.