我如何强制下载HTML和/或JavaScript? [英] How can I force download with html and/or javascript?
本文介绍了我如何强制下载HTML和/或JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这样的代码:
<a href="http://mysite.com/song.mp3">My Song</a>
我该怎么做才能让用户不必右键点击,另存为,他们只是点击链接并 BAM 下载?
How can I make it so that instead of the user having to right click, save as, they just click the link and BAM it downloads?
推荐答案
在服务器端,您可以发回 Content-Disposition
标题,它应该可以工作(尽管它不符合规范)。看到这里的例子:
On the server side, you can send back a Content-Disposition
header, which should work (although its off-spec). See example here:
将来您可以从新下载
属性,它是HTML5的一部分。
In future you'll be able to benefit from the new download
attribute, part of HTML5.
这篇关于我如何强制下载HTML和/或JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文