• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Close Popup Window after download completes

 
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am placing a link on a page, which when clicked, initiates a download on the client computer. I am doing this, by calling a new popup window, and then calling a javascript function onLoad in that popup page. The javascript clickes on a hidden link and invokes a bean method which leads to the download. Now i want to be able to close the popup window after the user has downloaded/cancelled the file. I want the popup window to close automatically after the download.
How can i do this? If this is not possible, can i do some simulation so that the window closes on some logical event?


Thanks
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you can't know when the download is complete. What is the point of this pop-up? Why not give them a link to download from the main window?
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne,

The file to be downloaded is not static, it is created after fetching a lot of data from the DB and then processing it. This takes some time, hence in order to not keep the user waiting, i am using a popup window. The user can then continue his work on the main window and navigate away from that page too, being prompted for the download after the file is ready.

Thanks.
 
Ranch Hand
Posts: 38
IntelliJ IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only problem is identifying if the download is complete. I don't think there is a possible way of doing that. Anyway is there any use of keeping the pop-up open untill the download is complete. You can simply close the pop-up once the download is initiated. Using below JavaScript, can't you?

 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ayoma,

Will this not lead to confusion to the user? I mean, as i said, the creation of the file to be downloaded can take anywhere between 2-10 minutes, so if we close the popup window as soon as the link is created, the user has to simply wait and watch. Also, i cannot understand how the file will be sent if the popup is closed, the data is written to the response stream of the wndow, right?

Thanks.
 
Ayoma Wijethunga
Ranch Hand
Posts: 38
IntelliJ IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.. That will not work, if generation of the download is taking that much of time. So the generation begins with the opening of pop-up.

What do you think about this approach:

  • Generation begins with the opening of pop-up
  • Progress of generation process is stored in a database or somewhere
  • AJAX request sent by pop-up, checks the progress of generation, for each 10 seconds or so
  • Progress of the generation process will be shown in pop-up. So user knows that everything is working fine.
  • Pop-up will close itself after the generation process was complete (where user will be prompt for the download)


  • This is the only solution I can see at the moment.

    Regards
     
    Ayoma Wijethunga
    Ranch Hand
    Posts: 38
    IntelliJ IDE Firefox Browser Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Wait.. Another problem. How were you planing to prompt user for the download once the generation is over? Did you use a AJAX request or???
     
    Ranch Hand
    Posts: 479
    1
    IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    I remember doing somthing similar. I popup the new window containing data to be printed call a window.print() using javascript and then call a window.close(). This met my requirement. To my knowledge the window.print() would send the document to the print queue and even if the window closes before the actual print operation it would not be affected.

    Cheers,
    Raj.
     
    Janardan Kelkar
    Ranch Hand
    Posts: 72
    Eclipse IDE Firefox Browser Suse
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi All,

    @Ayoma

    Once the file is created, it is written to the servletoutput stream. Here is the method that does this-

    This leads to the browser popup which prompts the user to open/save/cancel the file.

    @Raj

    I did not understand your concept, could you elaborate a little more?
    The file is not to be displayed in the window, it should be donwloadable to the local machine.

    Thanks All.
     
    Ayoma Wijethunga
    Ranch Hand
    Posts: 38
    IntelliJ IDE Firefox Browser Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    OK! Now it is much clear.

    Try this out. After calling "response.flushBuffer();" method it can be considered that the generation and prompt for download is complete. So user already has the download or "save as" windows opened, making it simply possible to close the popup without affecting rest of the operation.

    Add below line after "response.flushBuffer();"


    Here is the code for "closeWindow.htm"


    Note that "window.close()" method can only be used with pop-ups or winnows opened with "window.open()" method.
    Write back if this fail.

    Regards,

    PS - Raj was talking about the window.print() method used to take a printout of a page using a Printer. So I don't think that method will meet your requirements.
     
    Janardan Kelkar
    Ranch Hand
    Posts: 72
    Eclipse IDE Firefox Browser Suse
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Ayoma,
    I Tried this method. The popup window closes, but before the download popup appears to the user. I tried to put delays before "response.sendRedirect()", but still it seems that the sendRedirect method does not let the download popup to appear before it executes.!!

    Thanks.
     
    Ayoma Wijethunga
    Ranch Hand
    Posts: 38
    IntelliJ IDE Firefox Browser Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Now, we only have to place the response.sendRedirect() in the correct place. Did you try placing it after "facesContext.responseComplete();" .

    If this won't work, we'll have to take a deep look into the code. Some debugging will help to identify the location yourself.

    Regards.
     
    There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic