Javascript popup window question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonpfl
    New Member
    • Feb 2007
    • 31

    Javascript popup window question

    All,

    I am using javascript (window.open()) to create a popup to do some processing. This popup is going to create a PDF which can take anywhere from 10 secs to 2 mins (alot of backend SQL calls) and I was hoping to use this popup to show the user that something is going on (animated gif) and give them the ability to use the parent window to do other things in our system (while the popup is creating the PDF on the server).

    My problem lies in the fact that while the popup is creating the PDF, the parent window cannot navigate to other pages (until the popup window is done). Is there any way to disassociate the popup window with the parent window so a user will be able to navigate with the parent window while the popup window is processing?

    Thx
    jonpfl
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you could send an AJAX-call and just open the window when the server sends the response ... this is done in the onreadystatecha nge-callback - first just have a look at a basic AJAX-example and ask more questions about it when you have them :)

    kind regards

    Comment

    • jonpfl
      New Member
      • Feb 2007
      • 31

      #3
      I have never used ajax before.

      Is there a way to do with just javascript or am I going to have to get ajax?

      Thx
      jonpfl

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        AJAX is just javascript ;) ... by making use of the browsers XMLHttpRequest and its asynchronous behaviour ... with that you could achieve what you want ...

        kind regards

        Comment

        • jonpfl
          New Member
          • Feb 2007
          • 31

          #5
          Originally posted by gits
          AJAX is just javascript ;) ... by making use of the browsers XMLHttpRequest and its asynchronous behaviour ... with that you could achieve what you want ...

          kind regards
          Ok, let me get this straight.

          If I incorporate Ajax on my child/popup to create the PDF, my user is going to be able to go to the parent window and navigate to another page while the child/popup is awaiting a response from the server?

          Sorry if this is a total newbie question but I am new at this.

          Thx
          jonpfl

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            not exactly ... basicly you start a async XMLHttpRequest and say: open the window when you are ready ... the user may do whatever he wants in the meantime ...

            Comment

            • jonpfl
              New Member
              • Feb 2007
              • 31

              #7
              Originally posted by gits
              not exactly ... basicly you start a async XMLHttpRequest and say: open the window when you are ready ... the user may do whatever he wants in the meantime ...
              Now that you tell me this, I think I might want to do it another way (tell me which ones are feasible)

              1) User is on page1.asp and clicks a button to create a PDF. I use javascript to send an async call to the server to start creating the PDF (it is all vbscript with a bunch of stored procs). While the PDF is being created, I assume the user can navigate to page2.asp and do something else, correct? I was thinking that instead of using a popup window when completed, I could just email them the PDF using vbscript on the server. Does this sound doable? I assume I do not actually have to have a callback function, right?

              2) If I decide to use a popup window and user makes the request on page1.asp and has now changed to page2.asp, how would I handle that? I assume every possible page the user could navigate to in our internal app, I would have to have that callback function declared in the javascript, right? We currently have an include file called common.asp that I could it in since all our pages include that.

              Is there a specific version of Ajax you recommend for ASP? Right now, I am reading up on one called "Sarissa"

              Thx
              jonpfl

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                i think your first version sounds quite good ... but to clarify something: the callbackfunctio n is passed to the requestobject itself ... it mustn't be declared on every page ... and there is nothing like an ajax-version or something similar ... it is just javascript and xml and an instance of the XMLHttpRequest-Object of a browser ... there are just some frameworks out there that encapsulate the usage of all of this ...

                Comment

                • jonpfl
                  New Member
                  • Feb 2007
                  • 31

                  #9
                  Originally posted by gits
                  i think your first version sounds quite good ... but to clarify something: the callbackfunctio n is passed to the requestobject itself ... it mustn't be declared on every page ... and there is nothing like an ajax-version or something similar ... it is just javascript and xml and an instance of the XMLHttpRequest-Object of a browser ... there are just some frameworks out there that encapsulate the usage of all of this ...
                  Ok, I put some ajax in my javascript code

                  Code:
                              http_request = new XMLHttpRequest();
                              sURL = "ReportHeading=" + frmCreditReport.ReportHeading.value;
                              sURL += "&MeetingId=" + frmCreditReport.MeetingId.value;
                              http_request.onreadystatechange = jon;
                              http_request.open('POST', "popup_pdf.asp?" + sURL, true);
                              http_request.send(null);
                  
                  function jon()
                  {
                      if (http_request.readyState == 4)
                      { 
                          alert(http_request.responseText);
                      } 
                  }
                  And I can see that the PDF is getting created (I save it to a temp directory) but I still have the problem of not being able to navigate to another page. When I try to change to another page, my page waits until the Ajax is complete before continuing.

                  What am I doing wrong?

                  Thx
                  jonpfl

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    is it a large pdf? ... what if you just alert a string like 'foo'? may be the problem is the transfer of the response data and not the pdf-creation at all? presenting a download-link or send it per mail as you already suggested would workaround that?

                    Comment

                    • jonpfl
                      New Member
                      • Feb 2007
                      • 31

                      #11
                      Originally posted by gits
                      is it a large pdf? ... what if you just alert a string like 'foo'? may be the problem is the transfer of the response data and not the pdf-creation at all? presenting a download-link or send it per mail as you already suggested would workaround that?
                      Yes, it is a very large PDF

                      I cannot email it because I would have the same problem. When I am in the processing of creating it (~ 1 min), I cannot navigate with the calling window to other pages. Is there a way to do that?

                      IE : I am on an asp page and a user clicks a button to create a PDF. I send that request to the server for prcoessing. This process can take upwards of 2 mins and I want the user to be able to navigate to other pages while the PDF is being created. If I try to navigate away from the page that made the PDF request (in this case, via Ajax), it just hangs until the PDF creation process is completed.

                      Thx
                      jonpfl

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5390

                        #12
                        did you try the 'foo'-alert? ... in your case it seems to be a good idea to start the request, and update the page with a link to the created file at the server in the callback and let the user decide to download it ... this will typically be done with the browsers download-manager ... could that be an option? as i said ... the browser doesn't wait for the request, i guess he waits for the pdf-data transfer ...

                        kind regards

                        Comment

                        • jonpfl
                          New Member
                          • Feb 2007
                          • 31

                          #13
                          Originally posted by gits
                          did you try the 'foo'-alert? ... in your case it seems to be a good idea to start the request, and update the page with a link to the created file at the server in the callback and let the user decide to download it ... this will typically be done with the browsers download-manager ... could that be an option? as i said ... the browser doesn't wait for the request, i guess he waits for the pdf-data transfer ...

                          kind regards
                          Actually, I changed the callback function to a 'foo'-alert. I now see what is going on. If I start the request and it is processing in the background and I try to go to another website (ie www.google.com) , it lets me (and I assume the request to call the callback function is disregarded by the browser). BUT, if I try to navigate inside my webpage using the menu system someone else devised, it does not allow me to change pages.

                          Any idea why?

                          Thx
                          jonpfl

                          Comment

                          • gits
                            Recognized Expert Moderator Expert
                            • May 2007
                            • 5390

                            #14
                            hmmm ... is the page-menu responding in any way? does it reload the window onclick? in case the window is reloaded then i think the current request will be aborted ... do you have a testpage online, so that i could have a deeper look at it?

                            Comment

                            • jonpfl
                              New Member
                              • Feb 2007
                              • 31

                              #15
                              Originally posted by gits
                              hmmm ... is the page-menu responding in any way? does it reload the window onclick? in case the window is reloaded then i think the current request will be aborted ... do you have a testpage online, so that i could have a deeper look at it?
                              I wish I had a test page online but this is all internal work at the moment. I do notice that if I am creating a PDF on the server, I can enter an URL for another part of our system w/o using the menus and it works. If I try to navigate with our menus to the same page, it doesn't work.

                              I have a feeling something in our menuing system is funky and needs to be looked at. I can put the code up here if you want to look at it (I am fairly new at this stuff so alot of it doesnt make sense to me)

                              Thx for all your help to this point. You have been very helpful!!!

                              Comment

                              Working...