只有一个纯html和js文件,我怎么能强制链接到一个MP3下载,而不是只是玩? [英] with just a plain html and js file, how can i force a link to an mp3 to download instead of just play?

查看:150
本文介绍了只有一个纯html和js文件,我怎么能强制链接到一个MP3下载,而不是只是玩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个媒体文件(如mp3)的链接,我希望在用户点击它时下载它,而不仅仅是让文件播放。我想到的页面只是一个普通的静态html页面。



有什么想法?

解决方案为了做到这一点,你需要发送一个标题 Content-disposition:attachment;文件名= fname.ext 在发送文件之前用你喜欢的语言标题。

不知道具体内容,例如您的服务器配置使用哪种语言和哪种控制方式,我无法给您更详细的说明。不过,只能使用html和javascript来完成。


i have a link to a media file such as an mp3, and i want it to get downloaded when the user clicks on it, instead of just having the file get played. the page i have in mind is just a plain static html page.

any ideas?

解决方案

In order to make that happen you need to send a header with Content-disposition: attachment; filename=fname.ext header in your favorite language before sending the file.

Without knowing the specifics such as what language and what control you have over your server configuration I cannot give you more detailed instructions. You cannot do it with just html and javascript however.

这篇关于只有一个纯html和js文件,我怎么能强制链接到一个MP3下载,而不是只是玩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆