I need a cross-browser solution for the following use: The user clicks the "Export" button on one of our pages, which opens a pop-up window with the form. When submitting the form, the user should receive a binary file download (for example, a CSV file), and the pop-up should close without changing the visible contents of the parent window.
We cannot use the timeout to close the popup because there is usually a dialog box asking the user how to process the file before downloading it, and there is no way to find out how long the user will need to process this dialog.
We initially had a script in popup that sets window.location to the URL of the download file. This leaves the popup closed.
So, I tried putting the hidden iFrame in the parent window, and in the pop-up menu set iFrame src to the download URL before calling self.close (). This works fine in Firefox, but IE completely addresses security restrictions.
Is there a proper way to do this? How about a way to work with IE?
Update - issue resolved
The answers suggested here were not too far away, but my problem was a bit more complicated than just a problem with Javascript. I ran into errors with IE and Excel (since the CSV download file) and the popup did the form message.
URL ( GET POST), IE ( , ).
window.opener, URL- . window.close(). URL- window.location URL- ( iFrame IE , -, ).
URL Content-Type: application/octetstream Content-Disposition "," attachment; = filename.csv".