如何在网页上添加下载音乐链接? [英] How to add a download music link on webpage?

查看:277
本文介绍了如何在网页上添加下载音乐链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向用户展示如下所示的弹出窗口,当他点击下载音乐链接时?


如果我使用以下代码,点击链接后会打开浏览器嵌入的音乐如苹果RealTIme ..

 < a href =../ mp3 / horse.mp3target =_ blank >点击下载< / a> 

如何防止浏览器运行音乐(不禁用/删除此插件)。



我希望我的浏览器能够下载音乐并且不应该播放它! ,从锚点移除 onclick 属性。第二,让你的服务器返回一个 content-disposition:attachment 请求mp3时的HTTP响应头。你如何做到这一点取决于你的服务器。例如,在Apache中,如果不涉及服务器端编程语言,您可以使用 a Header 指令。或者,请参阅 Java示例(尽管您应该设置正确的 content-type for a mp3)。


I want to show user a popup like shown below when he clicks on a "Download music" link?

If I use following code then after clicking on a link opens up browser embedded Music player like Apple RealTIme..

<a href="../mp3/horse.mp3" target="_blank">Click to download</a>

How can I prevent browser from running Music (Without disabling/removing this plugin).

I want my browser should download Music and should not play it!

解决方案

First, remove the onclick attribute from the anchor. You don't need to involve JavaScript for this.

Second, have your server return a content-disposition: attachment HTTP response header when the mp3 is requested. How you do this depends on your server. For example, in Apache, without involving a server side programming language you can use a Header directive. Or, see an example in Java (although you should set the correct content-type for an mp3).

这篇关于如何在网页上添加下载音乐链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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