I'm looking for some more thoughts about the best way to initiate a file download from Javascript.
http://stackoverflow.com/questions/60590/best-way-to-initiate-a-download has a lot of good ideas which can be summarized:
- Set the src on an iframe
- Use window.location.replace()
- Use a page with a meta refresh header
- Use a window.open()
- Let the server directly output file, setting the Content-Type and Content-Disposition
- The iframe isn't working because of cookies set by the environment I'm using. I think I'd need to enable P3P headers to resolve this, but the environment doesn't allow me to set headers, so P3P is out
- The window.location.replace() works except that in IE8, the address bar of the window changes to the URL to the file and the underlying window is blank after the downloaded file is opened
- The meta refresh approach also works, but still the address bar changes to the URL of the file and the underlying window is blank after the file downloads
- I'm desperately trying to avoid window.open() to dodge any popup blocker problems
- The server environment I'm in won't allow you to output the file itself, like you could do in say, ASP.NET's Response object
I haven't even tried these methods with IE6 or IE7, so there may be other surprises there.
So does anyone have any other suggestions for initiating a download in IE, where (1) no popups are involved and (2) the file can be saved or opened and (3) no blank window is left behind, (3) using just Javascript, HTML and a URL to a file?
Denver Mike