opener.location.href multiple times

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • senort01
    New Member
    • Nov 2008
    • 12

    opener.location.href multiple times

    Hi,

    I spawn a window, process some information, and then issue opener.location .href to change the location of the parent information. I then close the child window. Works great.

    However, if the user then clicks on a link again on the redirected page and repeats the process (ie, processes more information) the opener.location .href does not change the parent window.

    All of the same code is getting executed. Can anyone tell me why repetitive opener.location .href's don't work for the same parent window?

    If the user does a manual reload of the page between spawning a new child window it works fine.

    Thanks.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you show some of the code or maybe a link?

    Explain the exact steps required to reproduce the problem.

    Comment

    • senort01
      New Member
      • Nov 2008
      • 12

      #3
      Sure.

      Very simple. I open the window with this:
      Code:
      <a href="/localFile?withVariables" onclick="window.open(this.href, 'editWindow', 'menubar=no, width=550, height=600, toolbar=no, scrollbars=yes'); return false;">Edit</a>
      After I process the data in the popup window I write just this HTML:
      Code:
      <html>
      <head>
      <script type="text/javascript">
      opener.location.href = "/openerScript?someVars#val";
      window.close();
      </script>
      </head>
      </html>
      So, basically, the original window URL plus I add the # so it jumps to an anchor.

      Works great on the first pass. Redirects the parent window to the right URL and jumps to the anchor. However, if you then reclick the edit link (without refreshing the page manually) it will open the popup, process the data and close but NOT redirect the parent window.
      Last edited by acoder; Feb 18 '09, 09:26 AM. Reason: Added [code] tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Is this the same page? Try changing the location after page load <body onload> or window.onload.. .

        Comment

        • senort01
          New Member
          • Nov 2008
          • 12

          #5
          Originally posted by acoder
          Is this the same page? Try changing the location after page load <body onload> or window.onload.. .
          Sorry, not sure I understand.

          The popup that is redirecting the parent is a different page. The parent gets redirected anytime a form is submitted in the popup and the popup closes (or, at least is supposed to).

          The parent window always gets redirected to the same file, but, technically could have a different URL because there is likely to be different variables. Though, perhaps the problem is that it's not reloading because the URL isn't changing? Does a opener.location .href just not refresh the page if it detects it is the same URL as the parent window already has? How do you deal with that if that's the case?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            By page load, I meant after the page has fully loaded. Your code currently changes the location during page load:
            Code:
            <html>
            <head>
            <script type="text/javascript">
            opener.location.href = "/openerScript?someVars#val";
            window.close();
            </script>
            </head>
            </html>
            Change it to something like:
            Code:
            <html>
            <head>
            <script type="text/javascript">
            function changeLoc() {
              opener.location.href = "/openerScript?someVars#val";
              window.close();
            }
            </script>
            </head>
            <body onload="changeLoc()">
            </body>
            </html>

            Comment

            Working...