在一个基于 PHP 的网站上,我想在用户填写一个简短的表格后向他们发送一个下载包。由站点启动的下载应该类似于像 download.com 这样的站点,它们说“您的下载将立即开始”。
我知道的几种可能的方法,以及浏览器兼容性(基于快速测试):
1)做一个window.open
指向新文件。
- FireFox 3 blocks this.
- IE6 blocks this.
- IE7 blocks this.
2) 创建一个指向新文件的 iframe。
- 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?
奖励:是否有不需要浏览器条件语句的方法?
(我相信 download.com 有条件地使用了这两种方法,但我无法让其中任何一种工作。)
回应和澄清:
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?"
更新:我已经放弃了这种方法。原因请参阅下面的答案。