在基于 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?"
更新:我已经放弃了这种方法。原因请看下面我的回答。
最佳答案
您还可以进行元刷新,大多数浏览器都支持。 Download.com 在 noscript 标签中放置了一个。
<meta http-equiv="refresh" content="5;url=/download.php?doc=123.zip"/>
关于php - 启动下载的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60590/