FireFox (version 2) Ajax call to update page times out if child window is closed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    FireFox (version 2) Ajax call to update page times out if child window is closed

    I have 2 FireFox (version 2) browser windows opened.

    One is the child of the other.

    When the user is finished with the child window, a method in the parent window is called to refresh a section of the page.

    This is the JavaScript code that I'm using to refresh the content in the parent page:
    Code:
    <script type="text/javascript">           
                function UpdateList() {
                    showUpdatingMessage();
                    document.getElementById('myHiddenFieldForStuff').value = true;
                    __doPostBack('myASPButtonClientID', '');
    }
     </script>
    Please note that the __doPostBack() method is supplied by ASP.NET. This method submits the page to the server and indicates that the control that caused this to happen was a button with the ClientID of "myASPButtonCli entID". This method determines whether or not the whole page should be updated or if an asynchronous call to the server should take place. Since the button with the clientID of "myASPButtonCli entID" is within an ASP.NET UpdatePanel, the __doPostBack() method preforms an asynchronous call to the server and only a portion of the page is updated.

    This is the JavaScript code in the child page that is used to call the UpdateList JavaScript method in the parent page:
    Code:
      <script type="text/javascript">
                window.onbeforeunload = CloseEvent;
              
                function CloseEvent() {
                    if (window.opener && !window.opener.closed) {
                        window.opener.UpdateList();
                    }
                }
                function CloseBrowserWindow() {
                    //window.close();
                    CloseEvent();
                }
            </script>
    The "CloseBrowserWi ndow" method is called when a Button is clicked. It's supposed to close the window, which triggers the window.onbefore unload event to fire, which calls the method in the parent window.

    Right now the JavaScript responsible for closing the browser window is commented-out. The reason is because in FireFox version 2, when the child window is closed, the postback to the server times out.

    When the child window remains opened, the request does not time out and everything works as it should (as it does in FireFox 3).

    I'm not sure why this is happening (in FireFox version 2..) It'd be nice to know the reason but I'm not expecting JavaScript experts to know the mysteries of FireFox (version 2)

    As a work around, I was thinking that if I were able to close the child window from the parent window the problem could be averted.

    The only thing is, I have no idea how to do this.

    I'd really appreciate any insight on this topic.

    Thanks,

    -Frinny
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    could you try to trigger the close event after the request is completed? i guess that the problem is that by closing the browser-window the reference to the current request object is dropped ... you could even try a timeout for the close-operation which should even avoid that behaviour ... i say i guess it because i don't know the exact reason but anytime we have that problem both of the solutions fix it ...

    may be i'll investigate it a bit and could give a better answer ;)

    kind regards

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by gits
      could you try to trigger the close event after the request is completed? i guess that the problem is that by closing the browser-window the reference to the current request object is dropped
      I'm not following? I don't understand what you're getting at here.....

      Originally posted by gits
      ... you could even try a timeout for the close-operation which should even avoid that behaviour ... i say i guess it because i don't know the exact reason but anytime we have that problem both of the solutions fix it ...
      I have no idea how long the update's going to take. It's a very complicate page with many things that need updating. So, it's not a very quick process...and when you combine that with a little bit of lag, how can you tell how long it's going to take?

      [edit]
      Oh wait, do you mean put put a timeout in the parent window to allow the close-operation in the child window to take place before raising the post back to the server?
      [/edit]

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        is UpdateList() an Ajax-operation? then you could just call to close the window in the callback of the request.

        in case you want to use the timeout then you just need a short one ... as i said ... it fixes such issues and i guess again :) that the timeout just avoids the reference dropping and let the browser instantiate and bind the requestobj correctly

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          regarding your edit ... i thought that something like this:

          Code:
          function CloseBrowserWindow() {
              CloseEvent();
              window.setTimeout(function() { 
                  window.close(); 
              }, 100);
          }
          should help.

          kind regards

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            So, you don't close the child window from the parent window then?

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              as far as i'm aware of this behaviour that doesn't matter ... it is a problem of closing a window 'the same time' when starting a request ... so it could be circumvented by using a timeout ... that is just the experience i made ..

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                I added the suggested code and it did not solve the problem.
                I'm still getting a time out message in the parent window if the client window is closed even though there is a timeout set.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Originally posted by gits
                  as far as i'm aware of this behaviour that doesn't matter ... it is a problem of closing a window 'the same time' when starting a request ... so it could be circumvented by using a timeout ... that is just the experience i made ..
                  This behaviour seems to be linked to my earlier question...

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    is it an Ajax-Request that does the update?

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      >>>quite response: yes............ ......<<<

                      Let's just say that I have no control over the Ajax request....

                      Well, I do but Please don't make me do it!
                      It's torture!

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5390

                        #12
                        ahh ... and please drop the onbeforeonload when using the timeout-solution ... does it work then? because this will start the request again ...

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          But then it won't be called when the user clicks the browser's "X" button.

                          Comment

                          • gits
                            Recognized Expert Moderator Expert
                            • May 2007
                            • 5390

                            #14
                            of course ... because that will close the window immediatly ... and we have the same problem again - does it work with the 'normal' button then?

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Testing...give me a sec (well few minutes as it times out)

                              Comment

                              Working...