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
When the compiler's not happy, ain't nobody happy.
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.
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?
This message was edited 2 times. Last update was at by Ayoma Wijethunga
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?
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???
Raj Kamal
Ranch Hand
Joined: Mar 02, 2005
Posts: 392
posted
0
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
Joined: May 05, 2008
Posts: 63
posted
0
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.
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.
This message was edited 1 time. Last update was at by Ayoma Wijethunga
Janardan Kelkar
Ranch Hand
Joined: May 05, 2008
Posts: 63
posted
0
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.!!