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 pletely useless to them.
How can I close this window and still be able to alert the user in IE9 that their download is plete and can be opened?
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 pletely useless to them.
How can I close this window and still be able to alert the user in IE9 that their download is plete and can be opened?
Share Improve this question edited Nov 30, 2011 at 16:05 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Nov 25, 2011 at 17:00 CaffGeekCaffGeek 22.1k18 gold badges105 silver badges186 bronze badges 5- 4 Couldn't you use an (hidden) iframe instead of a popup window? – Gerben Commented Nov 30, 2011 at 16:10
- 1 @Gerben, no, because the download could take a long time, it's an export in an application, I want it to happen in a separate window so that the user can continue using the application – CaffGeek Commented Nov 30, 2011 at 16:25
- Download shouldn't stop when the page is unloaded. The only problem would be if you need to upload a lot of data first. In that case the user can't leave the page until the upload is plete and the download dialog appears. – Gerben Commented Nov 30, 2011 at 16:30
- @Gerben, that's what I'm saying, that popup appears, and says "Generating download", that could take up to 5 minutes, then the download message appears and they can choose to download (after which I want to close the window automatically). However, if I put this in an iframe, then if during those 5 minutes the user changes pages, their download won't every appear. – CaffGeek Commented Nov 30, 2011 at 16:33
- You could poll the inner height of the window. If the info bar has appeared the innerheight should decrease. Then when the info bar dissapears the innerheight should return to the old value. (Assuming the bar disappears, and won't be replaced by a 'now downloading' progress bar. I don't use IE so I'm not sure.) – Gerben Commented Nov 30, 2011 at 16:47
3 Answers
Reset to default 3 +50Use an iframe - they work much better and you have more control. Simply set display: none;
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.
You could do an HTML ment to make your line that closes your popup only affect browsers that are not IE9... http://www.unintentionallyblank.co.uk/2006/09/19/if-internet-explorer-then-do-something-else-a-how-to/
<!--[If lt IE 9]>
<script>
//your code here
</script>
<![endif]-->
Should work. This if makes all versions of IE before 9 do the script you'll put inside of it. This must be in an HTML part.