Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE9, Downloads, Closing the popup

So, in my application the user can export their work to excel.

It works by opening a popup window (window.open(...)) which the parent then writes the data to a form, then posts the form back to the server.

The server generates the file, and streams it back down to the popup window where a download dialog appears. It also writes a cookie with a token.

This token, is unique to each download popup window, and when a window sees that cookie (Checking regularly) it closes itself with window.close() as the user has received the file download prompt.

This works great in IE7 and IE8

However, because IE9 decided to get rid of the dialog and replace it with an infobar, the window closes before the user can take action to download, and if they do click it, they never know when it's done without opening the downloads dialog manually.

As a temporary solution, the popup is no longer closed.

However, I want to be able to close it for the user as once their download has started it's completely useless to them.

How can I close this window and still be able to alert the user in IE9 that their download is complete and can be opened?

like image 396
CaffGeek Avatar asked Nov 25 '11 17:11

CaffGeek


2 Answers

Use an iframe - they work much better and you have more control. Simply set display: none;

like image 158
Tom van der Woerdt Avatar answered Sep 22 '22 07:09

Tom van der Woerdt


I did something like that just a little while ago. My solution was to get rid of the window.open and instead use Content-Disposition to coerce the browser to download the document instead of opening it.

Change your server code to insert this HTTP header before generating the Excel document, and then change all download buttons/links to ordinary links like <a href="server/document">Download the report as Excel</a>

Content-Disposition: attachment; filename=someFilename.xls

EDIT: Sorry, I missed the part with the five minute rendering time.

You could still use Content-Disposition for this with just a dash of Javascript. Have the server report back when the document is generated. Then just close the window opened by window.open, and have the main window load the document that has the Content-Disposition header.

like image 25
Anders Marzi Tornblad Avatar answered Sep 19 '22 07:09

Anders Marzi Tornblad