window.opener not correct when window reopened

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    window.opener not correct when window reopened

    I see this problem in IE but not Firefox.

    I have a page that opens a second page as a dialog box. If the Dialog
    is relaunched from a second instance on the page the Dialog window is
    reused, the controls are reinitialized but window.opener still refers to
    the original opener. I have simplified code than demonstrated the
    problem.

    This is the code for the base window which launches the dialog called
    Base.html:

    <html><head><ti tle>Base</title>
    <script language="javas cript">

    function launch(){

    var w = window.open(
    "dialog.htm l",
    "Dialog",
    "width=400,heig ht=389,scrollba rs=no,menubar=n o");
    w.focus();

    }

    function callBack(){
    alert("callBack : "+document.getE lementById("nam e").value);
    }

    </script>
    </head>
    <body>
    <input type="text" id="name"/n>
    <input type="button" onClick="launch ()" value="Launch" />
    </body>
    </html>

    You see it has a text box, a button and a couple of javascript
    functions. When you click the button the Dialog window is launched.

    The callBack function is called by the dialog window and throws up an
    alert with the contents of the text box. If you type different text
    into the text box of both you can then tell which one threw up the alert
    box.

    Here's the code for Dialog.html:

    <html><head><ti tle>Dialog</title>
    <script language="javas cript">

    function linkBack(){

    window.opener.c allBack();

    }

    </script>
    </head>
    <body>
    <p>Dialog</p>
    <input type="button" onClick="linkBa ck()" value="Link Back"/>
    </body>
    </html>

    Here we have a button and a javascript function that's called when the
    button is clicked. The Javascript function calls through window.opener
    to teh callBack function in the opener.

    In IE, launch 2 instances of Base.html. In the text box of one of them
    type X and click "launch". Then go to the 2nd instance, type Y and
    click "Launch". There will only be one instance of the Dialog but click
    the "Link Back" button in the Dialog and "callBack : X" will be
    displayed.

    You could throw some javascript in the onload method of the body tag is
    you want to convince yourselfe that the Dialog is actually being
    reloaded.

    Why isn't the window.opener property updated?

  • Lee

    #2
    Re: window.opener not correct when window reopened

    Dave said:[color=blue]
    >
    >I see this problem in IE but not Firefox.
    >
    >I have a page that opens a second page as a dialog box. If the Dialog
    >is relaunched from a second instance on the page the Dialog window is
    >reused, the controls are reinitialized but window.opener still refers to
    >the original opener. I have simplified code than demonstrated the
    >problem.
    >[/color]
    [color=blue]
    > function launch(){
    >
    > var w = window.open(
    > "dialog.htm l",
    > "Dialog",
    > "width=400,heig ht=389,scrollba rs=no,menubar=n o");
    > w.focus();
    >
    > }[/color]
    [color=blue]
    >Why isn't the window.opener property updated?[/color]


    IE is apparently noticing that you're loading the same URL
    in the window, and so is doing nothing. If you modify your
    base.html so that you can choose to load a different URL
    based on a checkbox state, you'll see that the opener is
    updated if the URL is different.

    A workaround would be to set w.opener=self in your launch()
    function. Put it after the call to focus(), so my suggestion
    won't be the line that fails if the window hasn't opened, yet.

    Comment

    • Lee

      #3
      Re: window.opener not correct when window reopened

      Lee said:[color=blue]
      >
      >Dave said:[color=green]
      >>
      >>I see this problem in IE but not Firefox.
      >>
      >>I have a page that opens a second page as a dialog box. If the Dialog
      >>is relaunched from a second instance on the page the Dialog window is
      >>reused, the controls are reinitialized but window.opener still refers to
      >>the original opener. I have simplified code than demonstrated the
      >>problem.
      >>[/color]
      >[color=green]
      >> function launch(){
      >>
      >> var w = window.open(
      >> "dialog.htm l",
      >> "Dialog",
      >> "width=400,heig ht=389,scrollba rs=no,menubar=n o");
      >> w.focus();
      >>
      >> }[/color]
      >[color=green]
      >>Why isn't the window.opener property updated?[/color]
      >
      >
      >IE is apparently noticing that you're loading the same URL
      >in the window, and so is doing nothing. If you modify your
      >base.html so that you can choose to load a different URL
      >based on a checkbox state, you'll see that the opener is
      >updated if the URL is different.
      >
      >A workaround would be to set w.opener=self in your launch()
      >function. Put it after the call to focus(), so my suggestion
      >won't be the line that fails if the window hasn't opened, yet.[/color]

      A more reliable work around might be to simply ensure that the
      URL is always unique (unless you're very fast)[untested]:

      var w = window.open(
      "dialog.html?"+ (new Date()).getTime (),
      "Dialog",
      ...

      Comment

      • Dave

        #4
        Re: window.opener not correct when window reopened

        I will try your suggestion but it seems that the page is reloading
        because I know that the body's onLoad method will be called.




        In article <cbaa4202kef@dr n.newsguy.com>, REM0VElbspamtra p@cox.net
        says...[color=blue]
        > Lee said:[color=green]
        > >
        > >Dave said:[color=darkred]
        > >>
        > >>I see this problem in IE but not Firefox.
        > >>
        > >>I have a page that opens a second page as a dialog box. If the Dialog
        > >>is relaunched from a second instance on the page the Dialog window is
        > >>reused, the controls are reinitialized but window.opener still refers to
        > >>the original opener. I have simplified code than demonstrated the
        > >>problem.
        > >>[/color]
        > >[color=darkred]
        > >> function launch(){
        > >>
        > >> var w = window.open(
        > >> "dialog.htm l",
        > >> "Dialog",
        > >> "width=400,heig ht=389,scrollba rs=no,menubar=n o");
        > >> w.focus();
        > >>
        > >> }[/color]
        > >[color=darkred]
        > >>Why isn't the window.opener property updated?[/color]
        > >
        > >
        > >IE is apparently noticing that you're loading the same URL
        > >in the window, and so is doing nothing. If you modify your
        > >base.html so that you can choose to load a different URL
        > >based on a checkbox state, you'll see that the opener is
        > >updated if the URL is different.
        > >
        > >A workaround would be to set w.opener=self in your launch()
        > >function. Put it after the call to focus(), so my suggestion
        > >won't be the line that fails if the window hasn't opened, yet.[/color]
        >
        > A more reliable work around might be to simply ensure that the
        > URL is always unique (unless you're very fast)[untested]:
        >
        > var w = window.open(
        > "dialog.html?"+ (new Date()).getTime (),
        > "Dialog",
        > ...
        >
        >[/color]

        Comment

        • Dr John Stockton

          #5
          Re: window.opener not correct when window reopened

          JRS: In article <cbaa4202kef@dr n.newsguy.com>, seen in
          news:comp.lang. javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Tue,
          22 Jun 2004 14:59:30 :[color=blue]
          >
          >A more reliable work around might be to simply ensure that the
          >URL is always unique (unless you're very fast)[untested]:
          >
          > var w = window.open(
          > "dialog.html?"+ (new Date()).getTime (),
          > "Dialog",
          > ...[/color]

          In the presence of clock-correcting software, time can repeat. It might
          be safer to define globally var Rabbit = 0 ; and to use
          "dialog.htm l?" + Rabbit++ ;

          That's not reliable, though, if the same dialog.html is opened from
          different local pages.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
          Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
          Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
          Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

          Comment

          • Dave

            #6
            Re: window.opener not correct when window reopened

            In article <cba9tl02jr7@dr n.newsguy.com>, REM0VElbspamtra p@cox.net
            says...
            [color=blue]
            > A workaround would be to set w.opener=self in your launch()
            > function. Put it after the call to focus(), so my suggestion
            > won't be the line that fails if the window hasn't opened, yet.[/color]

            This suggestion seems to have worked both in the sample application I
            posted and in teh real application it was derived from.

            Thanks a lot.

            Comment

            Working...