最好的方式来启动下载

最好的方式来启动下载

本文介绍了最好的方式来启动下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于PHP的网站上,我们希望在用户填写一个简短的表单后,向用户发送一个下载包。网站启动的下载应该类似于download.com这样的网站,它们说你的下载将在一会儿开始。

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)执行 window.open 指向新文件。

1) Do a window.open pointing to the new file.

- 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?

奖金:是否有一种不需要浏览器条件语句的方法?

Bonus: is there a method that doesn't require browser-conditional statements?

(我相信download.com有条件地使用这两种方法,但是我无法让任何一方工作。)

(I believe that download.com employs both methods conditionally, but I can't get either one to work.)

回应和说明:

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.

推荐答案

您还可以进行元刷新,大多数浏览器支持。 Download.com将一个放在noscript标签中。

You can also do a meta refresh, which most browsers support. Download.com places one in a noscript tag.

<meta http-equiv="refresh" content="5;url=/download.php?doc=123.zip"/>

这篇关于最好的方式来启动下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:04