On a PHP-based web site, I want to send users a download package after they have filled out a short form. The site-initiated download should be similar to sites like download.com, which say ‘your download will begin in a moment.’
A couple of possible approaches I know about, and browser compatibility (based on a quick test):
1) Do a window.open pointing to the new file.
- FireFox 3 blocks this. - IE6 blocks this. - IE7 blocks this.
2) Create an iframe pointing to the new file.
- FireFox 3 seems to think this is OK. (Maybe it's because I already accepted it once?) - IE6 blocks this. - IE7 blocks this. How can I do this so that at least these three browsers will not object?
Bonus: is there a method that doesn’t require browser-conditional statements?
(I believe that download.com employs both methods conditionally, but I can’t get either one to work.)
Responses and Clarifications:
Q: 'Why not point the current window to the file?' A: That might work, but in this particular case, I want to show them some other content while their download starts - for example, 'would you like to donate to this project?'
UPDATE: I have abandoned this approach. See my answer below for reasons.
You can also do a meta refresh, which most browsers support. Download.com places one in a noscript tag.